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 9124017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:28:39+00:00 2026-06-17T06:28:39+00:00

I want to create a new ImageData object in code. If I have a

  • 0

I want to create a new ImageData object in code. If I have a Uint8ClampedArray out of which I want to make an image object, what is the best way to do it?

I guess I could make a new canvas element, extract its ImageData and overwrite its data attribute, but that seems like a wrong approach.

It would be great if I could use the ImageData constructor directly, but I can’t figure out how to.

  • 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-17T06:28:41+00:00Added an answer on June 17, 2026 at 6:28 am

    This is interesting problem… You can’t just create ImageData object:

    var test = new ImageData(); // TypeError: Illegal constructor
    

    I have also tried:

    var imageData= context.createImageData(width, height);
    imageData.data = mydata; // TypeError: Cannot assign to read only property 'data' of #<ImageData> 
    

    but as described in MDN data property is readonly.

    So I think the only way is to create object and set data property with iteration:

    var canvas = document.createElement('canvas');
    var imageData = canvas.getContext('2d').createImageData(width, height);
    for(var i = 0; i < myData.length; i++){
        imageData.data[i] = myData[i];
    }
    

    Update:
    I have discovered the set method in data property of ImageData, so solution is very simple:

    var canvas = document.createElement('canvas');
    var imageData = canvas.getContext('2d').createImageData(width, height);
    imageData.data.set(myData);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a new Rally user with the following C# code DynamicJsonObject
I want to create one new model class, which will be extended in all
I have array with colors as its objects. I want to create an image
I want to create new instance of my custom PSObject. I have a Button
i want to create new file iam using this code try { File file
I have a multidimensional array and I want to create new variables for each
I have a multidimensional array and I want to create new variables based on
I have a Project, and now I want to create new unittest project for
I want create new table out of magento, in interface, without inheriting setup class.
I have following string. $option = '+'; $value = '100'; I want create new

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.