Elements on the canvas disappear w/ jsfiddle

丶灬走出姿态 提交于 2019-12-13 05:51:57

问题


I have a problem using fabric.js in canvas. After resize with scale factor at 5x, clicking in ZoomIn 2 times, the elements on the canvas disappear. Please look: http://jsfiddle.net/ptCoder/Q3TMA/90/

Canvas size (just for example):

<canvas id="c" width="400" height="400"></canvas>

Zoom Scale Factor:

var SCALE_FACTOR = 5;

Is there any solution?

Thank You.


回答1:


The problem is that you are also resizing the canvas, so after zooming 2 times, its size is 10000px * 10000px, meaning 100 megapixels, and several hundred megabytes of memory required.

If you keep the canvas size constant (like this), or limit it to a value small enough, zooming works as expected.

To keep the size constant you just have to remove these two lines:

canvas.setHeight(canvas.getHeight() * SCALE_FACTOR);
canvas.setWidth(canvas.getWidth() * SCALE_FACTOR);


来源:https://stackoverflow.com/questions/16201321/elements-on-the-canvas-disappear-w-jsfiddle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!