简体   繁体   English

使画布大小达到图像大小?

[英]Make a canvas the size of an image?

Im reading a file, checking it's exif data, adding to canvas and transforming if necessary. 我正在读取文件,检查它的exif数据,添加到画布并在必要时进行转换。

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. 这似乎默认将画布大小设置为默认的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 应该工作正常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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