Я хочу иметь функцию для моего активного объекта, в которой я могу увеличить фотографию.
Я попробовал код ниже, но проблема в том, что это занимает около 5 секунд, чтобы сделать это.
Как я могу увеличить производительность для увеличения и уменьшить это время.
zoomBy: function (x, y, z, canvasFabric, callback) {
debugger;
if (x || y) { this.zoomedXY = true; }
this.cx += x;
this.cy += y;
if (z) {
this.cw -= z;
this.ch -= z / (this.width / this.height);
}
if (z && !this.zoomedXY) {
// Zoom to center of image initially
this.cx = this.width / 2 - (this.cw / 2);
this.cy = this.height / 2 - (this.ch / 2);
}
if (this.cw > this.width) { this.cw = this.width; }
if (this.ch > this.height) { this.ch = this.height; }
if (this.cw < 1) { this.cw = 1; }
if (this.ch < 1) { this.ch = 1; }
if (this.cx < 0) { this.cx = 0; }
if (this.cy < 0) { this.cy = 0; }
if (this.cx > this.width - this.cw) { this.cx = this.width - this.cw; }
if (this.cy > this.height - this.ch) { this.cy = this.height - this.ch; }
this.rerender(canvasFabric, callback);
},
rerender: function (canvasFabric, callback) {
var img = new Image(), obj = this;
img.onload = function () {
debugger;
var canvas = fabric.util.createCanvasElement();
canvas.width = obj.width;
canvas.height = obj.height;
canvas.getContext('2d').drawImage(this, obj.cx, obj.cy, obj.cw, obj.ch, 0, 0, obj.width, obj.height);
img.onload = function () {
obj.setElement(this);
obj.applyFilters(canvasFabric.renderAll.bind(canvasFabric));
obj.set({
left: obj.left,
top: obj.top,
angle: obj.angle
});
obj.setCoords();
if (callback) { callback(obj); }
};
debugger;
img.src = canvas.toDataURL('image/png');
};
debugger;
img.src = this.orgSrc;
},
Я видел, что у некоторых других есть эта проблема, но не мог найти никакого решения для этого.
конечно есть ответ здесь
но я понятия не имею, как его использовать