HarmonyOS 使用image展示pixelMap无法展示图片 ,但有确切的值

HarmonyOS 使用image展示pixelMap无法展示图片 ,但有确切的值。

HarmonyOS
2024-10-10 12:03:07
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

示例如下:

import { image } from '@kit.ImageKit'  
import { BusinessError } from '@ohos.base'  
import { fileUri } from '@kit.CoreFileKit'  
import fs from '@ohos.file.fs';  
@Entry  
@Component  
struct IR240524155935058 {  
  imageUrl: string | null = null  
  @State imagePixelMap: image.PixelMap | null = null  
  @State imagePath: string | null = null  
  build() {  
    Column() {  
      if (true) {  
        Image(this.imagePixelMap)  
          .objectFit(ImageFit.Fill)  
          .width('100%')  
          .height('100%')  
          .onError((msg) => {  
            console.log('---图片加载失败', JSON.stringify(msg))  
          })  
          .onComplete((msg) => {  
            console.log('---图片加载成功', JSON.stringify(msg))  
          })  
      }  
    }  
  }  
  aboutToAppear(): void {  
    this.createImagePixelMap()  
  }  
  private async createImagePixelMap() {  
    if (true) {  
      const context: Context = getContext(this);  
      let imagePath: string = getContext().filesDir + '/img.jpg'  
      if (imagePath.length === 0) {  
        return  
      }  
      let imageSource: image.ImageSource = image.createImageSource(imagePath)  
      let decodingOptions: image.DecodingOptions = {  
        editable: true,  
        desiredPixelFormat: 3,  
      }  
      // 创建pixelMap  
      imageSource.createPixelMap(decodingOptions).then((pixelMap: image.PixelMap) => {  
        console.log("Succeeded in creating PixelMap")  
        this.imagePixelMap = pixelMap  
      }).catch((err: BusinessError) => {  
        console.error("Failed to create PixelMap")  
      });  
    }  
  }  
}
  • 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.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
分享
微博
QQ
微信
回复
2024-10-10 16:54:11
相关问题
HarmonyOS Image展示本地图片失败
1136浏览 • 1回复 待解决
HarmonyOS map无法展示
671浏览 • 1回复 待解决
HarmonyOS 地图无法展示
797浏览 • 1回复 待解决
HarmonyOS Toast无法展示
565浏览 • 1回复 待解决
HarmonyOS 地图组件无法展示
863浏览 • 1回复 待解决
HarmonyOS OAID弹窗无法展示
453浏览 • 1回复 待解决
HarmonyOS 实况窗无法展示问题
944浏览 • 1回复 待解决
地图组件无法正常展示
1487浏览 • 1回复 待解决