[英]JCanvas: How do I get the size of an Image?
I have drawn an image like this: 我已经绘制了这样的图像:
$("canvas").drawImage({
x: 0,
y: 0,
source: src,
draggable: true,
layer: true,
name: "image",
fromCenter: false,
}
});
The image shows as it should. 该图像按预期显示。 It is larger than the screen and I want to draw a much smaller rect (by the factor of .05) the sides of which are proportionate to the original image.
它比屏幕大,我想绘制一个更小的矩形(倍数为.05),其侧面与原始图像成比例。 How do I retrieve width and height of the above image?
如何获取以上图像的宽度和高度?
I tried: 我试过了:
var imageWidth = $("canvas").getLayer("image").width;
var imageHeight = $("canvas").getLayer("image").height;
But alert($("canvas").getLayer("image").width);
但是
alert($("canvas").getLayer("image").width);
returns null
. 返回
null
。 I also tried: 我也尝试过:
var imageWidth = $("canvas").getCanvasImage.width;
var imageHeight = $("canvas").getCanvasImage.height;
But alert($("canvas").getCanvasImage.width);
但是
alert($("canvas").getCanvasImage.width);
returns undefined
. 返回
undefined
。
You can use below statement to get height and width of canvas image 您可以使用以下语句获取画布图像的高度和宽度
var imageWidth = $("canvas").width();
var imageHeight = $("canvas").height();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.