Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8109373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:24:11+00:00 2026-06-06T01:24:11+00:00

Let’s say I have such PoC code snippet for working with canvas raw pixel

  • 0

Let’s say I have such PoC code snippet for working with canvas raw pixel data

(function(){
  'use strict';
  var img = document.createElement("canvas").getContext("2d").getImageData(0, 0, 1, 1);
  var imgData = img.data;
  img.data = imgData;
})();

The problem is that I get a reasonable error (I’ve checked in the latest Chrome and FF)

TypeError: Cannot assign to read only property 'data' of #<ImageData>

So, I can disable Strict Mode and everything will become perfect, but is there any possibility to implement this in Strict Mode? Maybe i just didn’t find a documentation on setter for data?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T01:24:12+00:00Added an answer on June 6, 2026 at 1:24 am

    Read comments in code:

    (function(){
      'use strict';
      var canvas=document.createElement("canvas");
      // canvas object must have size
      var w=canvas.width=100;
      var h=canvas.height=50;
      var ctx=canvas.getContext("2d");
      var imgData=ctx.getImageData(0,0,w,h);
      // In next line you retrieve array of RGBA values where each array element
      // is value between 0 and 255. Array size is size imgData.width*imgData.height
      var pixelData = imgData.data;
      pixelData[0] = 128; // Store 128 for Red channel of first pixel: (0,0)
      pixelData[5] = 128; // Store 128 for Green channel of second pixel
      imgData.data = pixelData; // Error
    })();
    

    You can also use putImageData method to modify content of CANVAS using another CanvasImageData object:

      var newImgData=ctx.createImageData(w,h);
      ctx.putImageData(newImgData,0,0);
    

    Read about CanvasImageData in MDN: https://developer.mozilla.org/en/DOM/ImageData and in MSDN: http://msdn.microsoft.com/en-us/library/ie/ff974957%28v=vs.85%29.aspx

    HTML5 canvas in MSDN: http://msdn.microsoft.com/en-us/library/ie/hh771733%28v=vs.85%29.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say we have this code: <form action='' method='POST' enctype='multipart/form-data'> <input type='file' name='userFile'><br> <input
Let's say I have this code: <p dataname=description> Hello this is a description. <a
Let say I have some code HTML code: <ul> <li> <h1>Title 1</h1> <p>Text 1</p>
Let's say I have the following function in C#: void ProcessResults() { using (FormProgress
Let's say I'm building a data access layer for an application. Typically I have
Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>
Let's say I have a drive such as C:\ , and I want to
Let's say we have a list such as: g = [123456789123456789123456, 1234567894678945678978998879879898798797, 6546546564656565656565655656565655656] I
Let's consider the following scenario: a function which can generate code colors from white
Let's say i have two tables in db: Car and Part. Car owns arbitrialy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.