简体   繁体   中英

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. 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); returns null . I also tried:

var imageWidth = $("canvas").getCanvasImage.width;
var imageHeight = $("canvas").getCanvasImage.height;

But alert($("canvas").getCanvasImage.width); returns undefined .

You can use below statement to get height and width of canvas image

var imageWidth = $("canvas").width();
var imageHeight = $("canvas").height();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM