newJS Posted December 15, 2020 Share Posted December 15, 2020 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); Quote Link to comment Share on other sites More sharing options...
grelf Posted December 15, 2020 Share Posted December 15, 2020 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? Quote Link to comment Share on other sites More sharing options...
newJS Posted December 15, 2020 Author Share Posted December 15, 2020 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.