Im using two html canvases, fronendCanvas is visible to users and is part of the html DOM tree and has 100% window width and height, the backendCanvas is created in javascript code and used to contain a huge chart that I need to draw.
/** FrontendCanvas */ // HTML <canvas id="canvas"></canvas> // JavaScript frontCanvas.width = window.innerWidth; frontCanvas.height = window.innerHeight; // CSS
Basically, in order to have smooth rendering, the frontendCanvas shows only part of the huge image drawn in the backendCanvas using the drawImage function (the user can use the mouse to drag the visualization area along the diagram, see the example Move HTML5 canvas with a background image ).
frontCanvas.getContext('2d').drawImage( backCanvas, (-ix - offsetX), (-iy - offsetY), (frontCanvas.width), (frontCanvas.height), 0, 0, (frontCanvas.width), (frontCanvas.height) );
When I set the width and height of the backendCanvas to 15000, everything works fine, but when I set it to the size that I really need, the width is 62322 and the height is 50946, somehow drawImage no longer works and gives a size error:
IndexSizeError: Index or size is negative or greater than the allowed amount (frontCanvas.height)
I assume Im will reach the maximum size of the canvas and reset it, but this is not like that because:
the link to the canvas says that the width and height of the canvas is unsigned length, so it’s much more than the numbers I mentioned;
I checked the size of the backendCanvas right before the call to the drawImage function, and that is correct.
Any help would be greatly appreciated!
Thanks.