HarmonyOS 鸿蒙Next关于使用createPixelMapSync中使用RGB_888生成图像不显示的问题

HarmonyOS 鸿蒙Next关于使用createPixelMapSync中使用RGB_888生成图像不显示的问题 我用createPixelMapSync中,如果使用参数RGBA_8888,能正常显示图片,但是如果使用RGB_888,就显示不了图片,如下面代码所示,调用testVoid正常,调用testVoid_2不正常。

完整代码如下:

import { image } from '@kit.ImageKit';
import ArrayList from '@ohos.util.ArrayList';

const TAG: string = "TestPage2"
@Entry
@Component
export struct TestPage2 {

  @State pixelMap: ArrayList<PixelMap> = new ArrayList()
  @State duration: number= 1000

  build() {
    Column(){
      Image(this.pixelMap[0]).width(200).height(200)
    }.width('100%')
  }

  aboutToAppear(){
    this.testVoid_2();
  }

  async testVoid(){
    let len = 100*100;
    let bytes = 4;
    let color = new Uint8Array(len*bytes)
    for(let i=0;i<len;i++){
      color[i*bytes] = 0x11;
      color[i*bytes+1] = 0x55;
      color[i*bytes+2] = 0xff;
      color[i*bytes+3] = 0xff;
    }

    let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888,
      size: { height: 100, width: 100 } , alphaType:image.AlphaType.OPAQUE}

    this.pixelMap = new ArrayList()
    this.pixelMap.add(image.createPixelMapSync(color.buffer, opts));
  }

  async testVoid_2(){
    let len = 100*100;
    let bytes = 3;
    let color = new Uint8Array(len*bytes)
    for(let i=0;i<len;i++){
      color[i*bytes] = 0x11;
      color[i*bytes+1] = 0x55;
      color[i*bytes+2] = 0xff;
    }

    let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGB_888,
      size: { height: 100, width: 100 } , alphaType:image.AlphaType.OPAQUE}

    this.pixelMap = new ArrayList()
    this.pixelMap.add(image.createPixelMapSync(color.buffer, opts));
  }
}

更多关于HarmonyOS 鸿蒙Next关于使用createPixelMapSync中使用RGB_888生成图像不显示的问题的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

这个是带透明通道的图片PixelMapFormat.RGBA_8888,

let opts: image.InitializationOptions = { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 100, width: 100 } , alphaType:image.AlphaType.OPAQUE}

你要创建PixelMapFormat.RGB_888,的很明显没透明度通道的这个alphaType删掉就好了

更多关于HarmonyOS 鸿蒙Next关于使用createPixelMapSync中使用RGB_888生成图像不显示的问题的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


关于HarmonyOS鸿蒙Next系统中createPixelMapSync方法使用RGB_888格式生成图像不显示的问题,可能的原因及解决方案如下:

  1. 像素数据问题:确保传递给createPixelMapSync的像素数据是有效的RGB_888格式数据。RGB_888格式意味着每个像素由三个8位分量组成,分别代表红、绿、蓝三种颜色。检查数据是否完整且未损坏。

  2. 图像尺寸问题:确认图像宽度、高度参数设置正确,且与像素数据的尺寸相匹配。错误的尺寸可能导致图像无法正确显示。

  3. 显示组件问题:检查用于显示图像的UI组件(如Image组件)是否正确设置并绑定了像素图。确保组件的显示属性(如可见性、大小等)正确无误。

  4. 渲染问题:确认系统的渲染管道没有异常,尝试在不同的设备或模拟器上运行以排除设备特定问题。

  5. 权限问题:检查应用是否拥有必要的权限来创建和操作像素图,特别是在涉及图形处理时。

如果以上检查均无误,但问题依旧存在,可能是由于系统bug或特定环境下的兼容性问题。此时,建议直接联系鸿蒙系统的官方技术支持团队进行深入排查。

如果问题依旧没法解决请联系官网客服,官网地址是 https://www.itying.com/category-93-b0.html

回到顶部