gol*_*nge 5 javascript html5-canvas fabricjs
我在调整图像大小时遇到问题。我想调整图像大小但不保持比例。当我使用 setHeight() 时,它给了我错误的值。
image.setHeight(100);
image.getHeight(); // gives me 140px output
Run Code Online (Sandbox Code Playgroud)
当我使用缩放功能时,一切都是正确的,但它也保持图像比例
image.scaleToHeight(100);
image.getHeight(); // correct 100px output
Run Code Online (Sandbox Code Playgroud)
这个测试还给了我奇怪的值:
console.log("h: " + image.getHeight()); // 348.25870646766174
image.set({ height : image.getHeight()-10 });
console.log("h: " + image.getHeight()); // 235.6030791317047
Run Code Online (Sandbox Code Playgroud)
编辑:
更多代码:
var flatImage = document.getElementById("flat-image");
var canvas = new fabric.Canvas("frame-canvas",{
width: 992,
height: 450
});
var image = new fabric.Image(flatImage, {});
image.selectable = false;
// image.scaleToWidth( 250 );
canvas.add(image);
canvas.centerObject(image);
canvas.renderAll();
console.log("h: " + image.getHeight()); // 334
image.set({ height : image.getHeight()-10 });
console.log("h: " + image.getHeight()); // 324 works good
Run Code Online (Sandbox Code Playgroud)
但是当我添加scaleToWidth()时,高度值变得很奇怪:
image.scaleToWidth( 250 );
console.log("h: " + image.getHeight()); // h: 166.66666666666666
image.set({ height : image.getHeight()-10 });
console.log("h: " + image.getHeight()); // h: 78.17697937458415
Run Code Online (Sandbox Code Playgroud)
基本上减半,然后减去给定值。
这是为什么 ?
| 归档时间: |
|
| 查看次数: |
5240 次 |
| 最近记录: |