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

HarmonyOS
2024-12-23 15:11:10
662浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

压缩图片尺寸见图片处理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.');
  }
})
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
分享
微博
QQ
微信
回复
2024-12-23 19:42:53


相关问题
HarmonyOS 如何汉字转换成拼音
949浏览 • 1回复 待解决
如何AndroidAPP转换成鸿蒙
319浏览 • 1回复 已解决
如何文件转换成字符串
1108浏览 • 1回复 待解决
如何某个时间转换成距现在时间
1215浏览 • 1回复 待解决
请问如何openblock文件转换成exe文件
3121浏览 • 0回复 待解决
HarmonyOS 日期如何转换成毫秒
699浏览 • 1回复 待解决
HarmonyOS 图片转换成ImageBitmap
988浏览 • 1回复 待解决
HarmonyOS 页面转换成图片
539浏览 • 1回复 待解决
HarmonyOS json转换成对象
935浏览 • 2回复 待解决
HarmonyOS Object怎么转换成map
689浏览 • 1回复 待解决
HarmonyOS 网络图片如何转换成PixelMap
685浏览 • 1回复 待解决
如何base64转换成图片?
11506浏览 • 2回复 待解决
Map类型怎么转换成Json string
3064浏览 • 1回复 待解决
HarmonyOS将对象转换成字符串方法
1576浏览 • 1回复 待解决
json 如何转换成自定义业务类对象
1551浏览 • 1回复 待解决
HarmonyOS image组件加载,加载缓慢
793浏览 • 1回复 待解决