【鸿蒙】【毛豆工具集】【图片】获取image.PixelMap对像的宽高及转vp

31 阅读1分钟

在研发的过程中,经常会使用图片的宽高进行计算,比如缩放图片,图片拼接,图片增加水印等。

下面的示例实现获取image.PixelMap对像的宽高及转vp

export function getImagePixelMapSize(imagePixelMap: image.PixelMap) : Size {
  const imageInfo: image.ImageInfo = imagePixelMap.getImageInfoSync();
  const height = px2vp(imageInfo.size.height) as number;
  const width = px2vp(imageInfo.size.width) as number;
  const size:Size = {width:width,height:height};
  return size;
}

调用时,传入image.PixelMap对像,返回该对像的宽高值(vp单位)