FabricJS克隆画布从矩形中删除小数 [英] Fabricjs cloning canvas removes decimals from rectangle

查看:91
本文介绍了FabricJS克隆画布从矩形中删除小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码可以在fabricjs中克隆画布:

I've got the following code which clones a canvas in fabricjs:

 var canvas = new fabric.Canvas('c');    
 canvas.width = 644.51234567;
 canvas.height = 644.51234567;
 var rect = new fabric.Rect({
       left: 0,
       top: 0,
       width: canvas.width,
       height: canvas.height,
       fill: 'rgba(255,127,39,1)',
       strokeWidth: 0
    });
canvas.add(rect);        
canvas.renderAll();

canvas.clone(function(cloneCanvas) {    
  canvas.forEachObject(function(obj) {
    alert("Width of original rect: "+obj.width);
  }); 
  cloneCanvas.forEachObject(function(obj) {
    alert("Width of cloned rect: "+obj.width);
  });
});

https://jsfiddle.net/s35fxaby/8/

通过运行代码可以看到,克隆画布会更改矩形上的小数位数. 这对我来说是个问题,因为我其余的代码取决于原始和重复的小数点是否相同.

As you can see by running the code, cloning the canvas changes the number of decimals on the rectangle. This is an issue for me as the rest of my code is dependent on the decimals being the same for the original and the duplicate.

对此我有什么能做的吗?例如防止克隆函数四舍五入吗?

Is there anything I can do about this - like preventing the clone function from rounding?

推荐答案

使用 NUM_FRACTION_DIGITS

fabric.Object.NUM_FRACTION_DIGITS = 10;

value =小数点后所需的位数.

value = number of digit you want after decimal.

默认值为2.

这篇关于FabricJS克隆画布从矩形中删除小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆