要获取使用 canvas 的 loadImage 加载的图片的大小,可以使用以下代码:

var img = new Image();
img.onload = function() {
  var width = img.width;
  var height = img.height;
  console.log('Image size: ' + width + 'x' + height);
};
img.src = 'path/to/image';

在上述代码中,我们创建了一个 Image 对象,并设置它的 onload 属性为一个回调函数,在图片加载完成后调用。在回调函数中,我们可以通过 img.width 和 img.height 属性获取图片的宽度和高度。

使用 Canvas 获取加载的图片尺寸

原文地址: https://www.cveoy.top/t/topic/nBia 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录