我的问题是我的图像大于3000 * 3000,我的画布尺寸为600 * 600,这是固定的,所以我使用scaleToHeight和scaleToWidth将图像适合在画布上,所以我的问题是我何时使用crop(clipTo)功能,然后图像无法根据我的预期结果进行裁剪,请帮助我,我想保持图像的原样
加载图片网址代码
window.fabric.Image.fromURL(`http://files.all-free-download.com//downloadfiles/wallpapers/5120_2880/big_tiger_16987.jpg`, (img) => {
img.set({
left: 0,
top: 0
});
img.scaleToHeight(600);
img.scaleToWidth(600);
canvas.add(img);
})
裁剪按钮代码
[![$("#btnCrop").click(function(e){
//console.log("hii");
var eLeft = cropBox.get('left');
var eTop = cropBox.get('top');
var left = eLeft - object.left;
var top = eTop - object.top;
left *= 1;
top *= 1;
var eWidth = cropBox.get('width');
var eHeight = cropBox.get('height');
var eScaleX = cropBox.get('scaleX');
var eScaleY = cropBox.get('scaleY');
var width = eWidth * 1;
var height = eHeight * 1;
object.clipTo = function (ctx) { $("#btnCrop").click(function(e){
//console.log("hii");
var eLeft = cropBox.get('left');
var eTop = cropBox.get('top');
var left = eLeft - object.left;
var top = eTop - object.top;
left *= 1;
top *= 1;
var eWidth = cropBox.get('width');
var eHeight = cropBox.get('height');
var eScaleX = cropBox.get('scaleX');
var eScaleY = cropBox.get('scaleY');
var width = eWidth * 1;
var height = eHeight * 1;
object.clipTo = function (ctx) {
ctx.rect(-(eWidth / 2) + left, -(eHeight / 2) + top, parseInt(width * eScaleX), parseInt(eScaleY * height));
}
$("#btnCropBox").show();
$("#btnCrop").hide();
fabricCanvas.remove(cropBox);
});
ctx.rect(-(eWidth / 2) + left, -(eHeight / 2) + top, parseInt(width * eScaleX), parseInt(eScaleY * height));
}
$("#btnCropBox").show();
$("#btnCrop").hide();
fabricCanvas.remove(cropBox);
});