javascript - 使用 Fabricjs 1.5.0 时 Canvas 中的图像模糊

标签 javascript cordova canvas fabricjs

这就是我的代码在 cordova 应用程序中使用 Fabricjs 时的样子

function onDeviceReady() {
    pictureSource=navigator.camera.PictureSourceType;
    destinationType=navigator.camera.DestinationType;
    capturePhoto();
    canvas = new fabric.Canvas('canvas', { width: window.innerWidth, height: window.innerWidth });
    canvas.renderAll();
    ctx=canvas.getContext("2d");
}

function onPhotoDataSuccess(imageData) {canvas.setBackgroundImage('data:image/jpeg;base64,'+imageData,canvas.renderAll.bind(canvas),{
originX: 'left',
originY: 'top'
  });
  }

 function capturePhoto() {
  navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 100,
    allowEdit : true,
    saveToPhotoAlbum: true, 
    correctOrientation: true,
    destinationType: destinationType.DATA_URL,
    cameraDirection: 0});

}

<canvas id="canvas" style="position:absolute; top:0px; left:0px;"></canvas>

但是,拍摄照片后, Canvas 窗口上的照片最终变得模糊。有谁知道为什么会发生这种情况吗?

附注使用fabricjs 1.6.0rc时,图像不再显得模糊,但1.5.0具有我需要的功能

最佳答案

为避免织物 1.5.0 的图像模糊,覆盖图像对象的标准描边宽度值:

fabric.Image.prototype.strokeWidth = 0;

你应该没问题。

在加载库之后、加载图像之前,在脚本中的任意位置添加这行代码。

如果在 devicePixelRation 不同于 1 的手机上工作,请尝试查看是否

canvas.enableRetinaScaling = true; // OR false 

有任何区别。

关于javascript - 使用 Fabricjs 1.5.0 时 Canvas 中的图像模糊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35112585/

相关文章:

javascript - 如何在 Canvas 元素上正确应用 globalCompositeOperation?

javascript - HTML5 canvas 缩放我的绘图

javascript - fadeIn() 不适用于一组 div

javascript - 使用 Meteor 中的 Javascript 事件在多个预设字段之间切换 MongoDB 文档

Javascript,使用函数作为递归深度计数器

javascript - 返回值未定义

JavaScript 超时

javascript - 从模态 Bootstrap 调用操作

cordova - 使用 ionic 框架从设备检索设备 token

jquery - Fabric.js 元素中的 flex 文本