【发布时间】:2017-07-11 05:27:12
【问题描述】:
我在使用 FabricJS 的画布上有一个图像,加载图像后我调用 canvas.centerObject(img)。我有相同的图像缩放 2X,我正在尝试实现放大镜功能,一切正常,无需居中图像,但是一旦我调用 canvas.centerObject(img),更大的图像就不会显示在正确的位置。
fabric.Image.fromURL('http://fabricjs.com/assets/pug_small.jpg', function (img) {
img1 = img;
img.set({
width: originalWidth,
height: originalHeight,
evented: true,
selectable: false
});
lens = fabric.util.object.clone(img);
lens.set({
width: scale * originalWidth,
height: scale * originalHeight,
clipTo: function (ctx) {
ctx.arc(-this.left + x - this.width / 2, -this.top + y - this.height / 2, radius, 0, Math.PI * 2, true);
}
});
canvas.add(img, lens);
canvas.centerObject(img);//*******issue here****
});
canvas.on('mouse:move', function (e) {
x = e.e.layerX;
y = e.e.layerY;
lens.set('left', -(scale - 1) * x);
lens.set('top', -(scale - 1) * y);
canvas.renderAll();
});
谢谢。
【问题讨论】:
标签: javascript image image-processing html5-canvas fabricjs