Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image FabricJ中缩小的图像是像素化的_Image_Resize_Fabricjs - Fatal编程技术网

Image FabricJ中缩小的图像是像素化的

Image FabricJ中缩小的图像是像素化的,image,resize,fabricjs,Image,Resize,Fabricjs,当我加载一个像我所包含的400 dpi高的图像时,它会变得非常像素化。我环顾四周,似乎什么也没用。我有一组用户可以放在画布上的图像,这些图像会根据比例重新调整大小,因此我无法提前调整它们的大小 任何帮助都将不胜感激 谢谢 朱迪 从1.4.13版开始,FabricJs支持图像大小调整过滤器 调整大小过滤器可通过两种方式使用: -使用固定比例加载时静态调整大小 var theImage = new fabric.Image(imag, { top: 0, left: 0 }); th

当我加载一个像我所包含的400 dpi高的图像时,它会变得非常像素化。我环顾四周,似乎什么也没用。我有一组用户可以放在画布上的图像,这些图像会根据比例重新调整大小,因此我无法提前调整它们的大小

任何帮助都将不胜感激

谢谢 朱迪


从1.4.13版开始,FabricJs支持图像大小调整过滤器

调整大小过滤器可通过两种方式使用:

-使用固定比例加载时静态调整大小

var theImage = new fabric.Image(imag, {
    top: 0,
    left: 0
});
theImage.filters.push(
               new fabric.Image.filters.Resize({
                        resizeType: 'hermite',
                        scaleX: 0.1,
                        scaleY: 0.1
                       })
                     );
theImage.applyFilters();
canvas.add(theImage);
-通过鼠标拖动按代码o缩放图像对象时动态调整大小

到目前为止,共实施了4个过滤器:

-SliceHack,不是真正的过滤器,而是一种通过多次调整图像大小0.5来获得更平滑大小的技巧

-埃尔米特滤波器

-双线性滤波

-使用波瓣参数调整Lanczos尺寸

以下是一些例子:

  • 使用Hermite过滤器静态调整负载大小,固定比例

    var theImage = new fabric.Image(imag, {
        top: 0,
        left: 0
    });
    theImage.filters.push(
                   new fabric.Image.filters.Resize({
                            resizeType: 'hermite',
                            scaleX: 0.1,
                            scaleY: 0.1
                           })
                         );
    theImage.applyFilters();
    canvas.add(theImage);
    
  • 使用Lanczos过滤器动态调整大小,2个波瓣

    var theImage = new fabric.Image(imag, {
        top: 0,
        left: 0
    });
    theImage.resizeFilters.push(new fabric.Image.filters.Resize({
        resizeType: 'lanczos', // typo fixed
        lanczosLobes: 2 // typo fixed
    }));
    canvas.add(theImage);
    

  • 如果您想将宽度设置为1500,那么下面的代码可用于rezise。这对我有用。图像看起来正常

    var scale = 1500 / oImg.getWidth();
    
    var newWidth = oImg.getWidth() * scale;
    var newHeight = oImg.getHeight() * scale;
    
    oImg.set({width : newWidth, height : newHeight});
    

    首先,在Fabric 2中,您可以像这样设置大小调整过滤器:
    image.resizeFilter=new Fabric.image.filters.resizeFilter({type:'hermite'})查看答案未解决OP的实际问题。