Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 制作一幅图像大小的画布?_Javascript_Html_Canvas_Html5 Canvas - Fatal编程技术网

Javascript 制作一幅图像大小的画布?

Javascript 制作一幅图像大小的画布?,javascript,html,canvas,html5-canvas,Javascript,Html,Canvas,Html5 Canvas,我正在读取一个文件,检查它的exif数据,添加到画布,必要时进行转换 我需要保持画布与原始图像的大小相同,我尝试了以下方法: ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, img.width, img.height); 这似乎将画布大小默认为300 x 150 如何使画布达到图像的大小 ctx.canvas.width = img.width ctx.canvas.height = img.height 应该可以

我正在读取一个文件,检查它的exif数据,添加到画布,必要时进行转换

我需要保持画布与原始图像的大小相同,我尝试了以下方法:

ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, img.width, img.height);
这似乎将画布大小默认为300 x 150

如何使画布达到图像的大小

ctx.canvas.width = img.width
ctx.canvas.height = img.height
应该可以