可以以颜色创建pixelmap吗

可以以颜色创建pixelmap吗

HarmonyOS
2024-08-13 16:13:01
634浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-image-V5#imagecreatepixelmap8可以使用image.createPixelMap来以颜色创建pixelmapl

import image from '@ohos.multimedia.image'; 
 
@Entry 
@Component 
export struct PixelMapTest { 
  @State pixelMap: PixelMap | undefined = undefined; 
 
  aboutToAppear(): void { 
    const color = new ArrayBuffer(255 * 255 * 4); // 这里与设置颜色的大小有关,等于宽*高*4,宽高在下面的size处设置 
    const colorInfo: Uint8Array = new Uint8Array(color); 
    console.log("colorinfo length:" + colorInfo.length); 
    for (let i = 0; i < colorInfo.length; i += 4) { 
      // b 
      colorInfo[i] = 0; 
      // g 
      colorInfo[i + 1] = 0; 
      // r 
      colorInfo[i + 2] = 255; 
      // a 
      colorInfo[i + 3] = 255; 
    } 
    image.createPixelMap(colorInfo.buffer, { editable: true, pixelFormat: 4, size: { height: 255, width: 255 } }) 
      .then((pixelMap) => { 
        this.pixelMap = pixelMap; 
      }) 
  } 
 
  build() { 
    Column() { 
      Image(this.pixelMap).width(200) 
        .height(200) 
    } 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
分享
微博
QQ
微信
回复
2024-08-13 21:19:00


相关问题
ArkUI转场动画可以颜色
2786浏览 • 1回复 待解决
HarmonyOS 可以创建内部类
911浏览 • 1回复 待解决
HarmonyOS 怎么改pixelmap颜色
605浏览 • 1回复 待解决
HarmonyOS可以在C代码中创建子线程
3318浏览 • 1回复 待解决