HarmonyOS 如何获取将大image转换成等比例的小图?

如题:HarmonyOS 如何获取将大image转换成等比例的小图?

阅读 531
1 个回答

压缩图片尺寸见图片处理api:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-image-V5

设置解码参数DecodingOptions的desiredSize:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-image-V5\#decodingoptions7

使用createPixelMap按照DecodingOptions创建PixelMap:

let decodingOptions : image.DecodingOptions = {
  sampleSize: 1,
  editable: true,
  desiredSize: { width: 1, height: 2 },
  rotate: 10,
  desiredPixelFormat: 3,
  desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 },
  index: 0
};
imageSourceApi.createPixelMap(decodingOptions, (err : BusinessError, pixelMap : image.PixelMap) => {
  if (err != undefined) {
    console.error(`Failed to create pixelMap.code is ${err.code},message is ${err.message}`);
  } else {
    console.info('Succeeded in creating pixelMap object.');
  }
})
logo
HarmonyOS
子站问答
访问
宣传栏