简体   繁体   中英

Make a canvas the size of an image?

Im reading a file, checking it's exif data, adding to canvas and transforming if necessary.

I need to keep the canvas the same size as the original image, I've tried this:

ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, img.width, img.height);

This seems to default the canvas size to the default of 300 x 150.

How can I make the canvas the size of the image?

ctx.canvas.width = img.width
ctx.canvas.height = img.height

Should work fine

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