如何写精华回答,获更多曝光?
发布
HarmonyOS中使用ArrayBuffer 构造PixelMap 数据报错问题?根据文档流程处理如下,构造 Uint8Array -> ArrayBuffer -> image.ImageSource -> image.PixelMap , 在会后环节仅提示创建失败,简化数据后代码如下:
let uInt8Arr = new Uint8Array(8)
uInt8Arr[0] = 161;
uInt8Arr[1] = 153;
uInt8Arr[2] = 151;
uInt8Arr[3] = 255;
uInt8Arr[4] = 160;
uInt8Arr[5] = 152;
uInt8Arr[6] = 150;
uInt8Arr[7] = 255;
let retBuffer = uInt8Arr.buffer;
const retImgSource : image.ImageSource = image.createImageSource(retBuffer);
// 创建pixelMap并进行简单的旋转和缩放
retImgSource.createPixelMap({desiredPixelFormat : image.PixelMapFormat.RGBA_8888}).then((pixelMap : image.PixelMap) => {
console.log("Succeeded in creating PixelMap")
}).catch((err : BusinessError) => {
console.error("Failed to create PixelMap",err)
});