Jump to content

Javascript PutImageData(GetImageData) pixel limit


Recommended Posts

I use putImageData and getImageData functions in my project. But I think I came across a limit when using them. I searched but could not find any information about it.

There seems to be a limit of 65536 on Chrome and 32768 on Firefox. Does anyone have any information about this?

The variable "pixelLength" in the example does not give an output when set to 65536.

 

var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var pixelLength = 65535;

var wf = document.createElement("canvas");
wf.width = pixelLength;
wf.height = 16;
var ctx_wf = wf.getContext("2d");

function CreateImageData() {
    var data = ctx_wf.createImageData(pixelLength, 1);
    for (var i = 0; i < data.data.length; i += 4) {
        data.data[i + 0] = 255;
        data.data[i + 1] = 0;
        data.data[i + 2] = 0;
        data.data[i + 3] = 255;
    }
    return data;
}

var imgData = CreateImageData();
ctx_wf.putImageData(imgData, 0, 0);

var width = c.width;
var height = c.height;

ctx.drawImage(ctx_wf.canvas, 0, 0, pixelLength, wf.height, 0, 0, width, height);

 

Link to post
Share on other sites

Interestingly MDN (at https://developer.mozilla.org/en-US/docs/Web/API/ImageData ) which I regularly use as the best reference, makes no mention of any such limitation. Each parameter is supposed to be unsigned long (4 bytes). However, do you really have a use for an image which is more than 32k wide or high?

Link to post
Share on other sites

It can actually be thought of as a waterfall where data flows. The data I get will generally be between 50k-100k. I will draw them on a different canvas in the background and reflect them on the screen in accordance with the size of the canvas displayed.

But I started to think that there was such a limit. I felt the need to ask because I could not find a source.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...