我有500x500的大畫布,圖片(最初500x500)縮小到300x200。它工作正常,但我想減少畫布,以便只顯示原始圖像的中心部分。這可能嗎?如何使用fabric.js庫減少畫布以僅顯示圖像的中心部分?
當前的代碼。
var canvas = new fabric.Canvas("myCanvas");
var img = new Image();
img.onload=function(){
var image = new fabric.Image(img,{name:"mainImage"});
image.set({
left:100,
top: 100,
angle: 0,
padding:10,
height:200,
width:300,
cornersize:10
});
}
img.src = imageUrl;
canvas.add(image);
canvas.renderAll();
在此先感謝。
檢查這些功能:http://fabricjs.com/docs/fabric.StaticCanvas.html#centerObject http://fabricjs.com/docs/fabric.StaticCanvas.html#centerObjectH http://fabricjs.com /docs/fabric.StaticCanvas.html#centerObjectV – ptCoder 2015-03-19 12:00:16
ptCoder你的鏈接建議工作的對象的位置,但需要顯示中心部分對象內部的圖像(300 x 200)我的原始圖像尺寸是原始大小:500 x 500.我想從中心部分的原始圖像到300 x 200分辨率。 – 2015-03-20 04:34:22