【鸿蒙实战开发】HarmonyOS对各种图片编解码格式的支持

场景一:展示系统原生支持的图片格式编解码的代码实现

// 获取resourceManager资源管理
const context : Context = getContext(this);
const resourceMgr : resourceManager.ResourceManager = context.resourceManager;
// 创建ImageSource
resourceMgr.getRawFileContent('test.jpg').then((fileData : Uint8Array) => {
  console.log("Succeeded in getting RawFileContent")
  // 获取图片的ArrayBuffer
  const buffer = fileData.buffer.slice(0);
  const imageSource : image.ImageSource = image.createImageSource(buffer);
}).catch((err : BusinessError) => {
  console.error("Failed to get RawFileContent")
});
// 创建PixelMap
imageSource.createPixelMap().then((pixelMap: image.PixelMap) => {
   console.log("Succeeded in creating PixelMap")
}).catch((err : BusinessError) => {
   console.error("Failed to creating PixelMap")
});

场景二:使用第三方库进行系统原生不支持的常用图片格式解码进行解码

avif格式

2.1 将libavif库添加到工程中,参考链接: libavif三方库说明

2.1.1 编译第三方库

下载本仓库

git clone https://gitee.com/openharmony-sig/tpc_c_cplusplus.git --depth=1

三方库目录结构

o    tpc_c_cplusplus/thirdparty/libavif   #三方库libavif的目录结构如下
o    ├── docs                               #三方库相关文档的文件夹
o    ├── HPKBUILD                           #构建脚本
o    ├── HPKCHECK                           #自动化测试脚本
o    ├── SHA512SUM                          #三方库校验文件
o    ├── README.OpenSource                  #说明三方库源码的下载地址,版本,license等信息
o    ├── README_zh.md                       #三方库说明文档
├── OAT.xml                            #开源扫描相关文件
  • 在tpc_c_cplusplus/lycium目录下编译三方库

编译环境的搭建参考 准备三方库构建环境

cd tpc_c_cpluspl
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值