Fabric js render of big image gives pixelated results

痴心易碎 提交于 2021-01-28 11:10:32

问题


I have to fit a big image (8000x6500) into a 800x650 canvas When I try to render the image simply using canvas.add() and having the image render at its 100% scale the resulting image is much more pixelated/blurred compared to the original one.

This is the code I'm using (only the image is a little bit smaller but you can still see the issue):

const canvas = new fabric.Canvas('c', { imageSmoothingEnabled: false });
fabric.Image.fromURL('http://cms.web.cern.ch/sites/cms.web.cern.ch/files/styles/large/public/field/image/LHC_and_mountains-0503019-1-nice.jpg', (image) => {
    image.left = -3000;
  image.top = -3500;
    canvas.add(image);
});

you can see an example jsfiddle here

As a comparison, this is how you see it with konva


回答1:


Disabling objectCaching on your image will fix the pixelation issue. Fabric enables objectCaching on images by default, which means that your enormous image is being drawn on a massive offscreen canvas that's as big as the image itself and is likely hitting the browser's max canvas size.

More on fabric's object caching here: http://fabricjs.com/fabric-object-caching

https://jsfiddle.net/melchiar/edjguh3L/



来源:https://stackoverflow.com/questions/52798525/fabric-js-render-of-big-image-gives-pixelated-results

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