一、导语
文章中代码都是本人亲测,可以直接复制粘贴使用
二、pixelMap转ArrayBuffer和base64
import { image } from '@kit.ImageKit';
let pixelMap: image.PixelMap | undefined = undefined;// 这里需要替换为已知的pixelMap数据
const imagePackerApi: image.ImagePacker = image.createImagePacker()
let packOpts: image.PackingOption = { format: 'image/jpeg', quality: 30 }
imagePackerApi.packing(pixelMap, packOpts).then((readBuffer)=>{
// readBuffer即为转化得到的ArrayBuffer
let bufferArr = new Uint8Array(readBuffer)
let help = new util.Base64Helper
// 转化得到的base64
let base = help.encodeToStringSync(bufferArr)
});
三、base64转pixelMap(更新中)