简体   繁体   English

使用drawImage,最大宽度调整图像大小以适合画布

[英]Resize Image to Fit to Canvas using drawImage, Max Width

I'm working with some large images (Wide but not high) and resizing them to fit to a canvas using the the drawImage Function. 我正在处理一些大图像(宽但不高),并使用drawImage函数调整它们的大小以适合画布。

ctx.drawImage(img,0,0,IW,IH,0,0,CW,CH);

I noticed some images do not load correctly. 我注意到某些图像无法正确加载。 After some investigation it appears to be only on images where IW > 16384. 经过一些调查,它似乎仅在IW> 16384的图像上。

If there is no resizing, the canvas is the correct size for the image, then it works. 如果没有调整大小,则画布是图像的正确尺寸,然后可以使用。

Does anyone know the limits of these parameters? 有人知道这些参数的限制吗?

Thanks for the help! 谢谢您的帮助!

I solved my problem by some rudimentary tiling 我通过一些基本的方法解决了我的问题

if (IW > 16000) {
   ctx.drawImage(img, 0, 0, IW/2, IH, 0, 0, CW/2, CH);
   ctx.drawImage(img, IW/2, 0, IW/2, IH, CW/2, 0, CW/2, CH);
} else {
   ctx.drawImage(img, 0, 0, IW, IH, 0, 0, CW, CH);
}

Though I'm still unware of the fundamental restriction on drawImage size 虽然我仍然不知道对drawImage大小的基本限制

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

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