HarmonyOS SVG转换pixelMap

转换会报错

[ImageSource]check mismatched format :image/svg+xml.
08-16 10:21:42.076   15239-15359  C02B60/com.exam...pFormatAgent com.examp...lication  I     not wbmp image format.
08-16 10:21:42.076   15239-15359  C02B61/com.exa...n/ImageSource com.examp...lication  E     [ImageSource]check mismatched format :image/vnd.wap.wbmp.
08-16 10:21:42.076   15239-15359  C02B61/com.exa...n/ImageSource com.examp...lication  E     [ImageSource]check mismatched format :image/webp.
08-16 10:21:42.076   15239-15359  C02B61/com.exa...n/ImageSource com.examp...lication  I     [ImageSource]image default to raw format.
08-16 10:21:42.082   15239-15359  C02B60/com.exa...ion/RawStream com.examp...lication  E     GetData, read want:5000, real:916
08-16 10:21:42.082   15239-15359  C02B60/com.exa...on/RawDecoder com.examp...lication  E     DoDecodeHeader header decode fail, ret=[62980103]
08-16 10:21:42.082   15239-15359  C02B60/com.exa...on/RawDecoder com.examp...lication  E     [GetImageSize]decode header error on get image size, ret:62980103.
08-16 10:21:42.082   15239-15359  C02B61/com.exa...n/ImageSource com.examp...lication  E     [ImageSource]decode the image info fail.
08-16 10:21:42.082   15239-15359  C02B61/com.exa...n/ImageSource com.examp...lication  E     [ImageSource]image info decode fail, ret:62980116.

测试代码如下:

async testSvgPixelMap(wi:number,hi:number,isPx:boolean =false){
  const wiPx = isPx?wi:vp2px(wi)
  const hiPx = isPx?hi:vp2px(hi)
  let decodingOptions : image.DecodingOptions = {
    editable: true,
    //转换RGBA_8888
    desiredPixelFormat: image.PixelMapFormat.UNKNOWN,
    desiredSize:{width:wiPx,height:hiPx},
    desiredDynamicRange: image.DecodingDynamicRange.AUTO
  }
  const resourceMgr = getContext(this).resourceManager;
  let sourceOptions: image.SourceOptions =
    { sourceDensity: 120, sourcePixelFormat: image.PixelMapFormat.RGBA_8888 };
  let  imgRes:ResourceStr = $r('app.media.camera_stroke_exposure_slide_brightness')
  let img = await resourceMgr.getMediaContent(imgRes);
  let imageSource = image.createImageSource(img.buffer.slice(0, img.buffer.byteLength),sourceOptions);
  if(!imageSource){
    console.error("imageSource undefined")
  }else{
    console.error(`imageSource size height`)
  }
  imageSource.createPixelMap(decodingOptions).then((pixelMap : image.PixelMap) => {
    console.log("Succeeded in creating PixelMap")
  }).catch((err : BusinessError) => {
    console.error("Failed to create PixelMap")
  });

}
HarmonyOS
5天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zxjiu

在代码中将 <?xml version="1.0" encoding="UTF-8"?>标签删除后,SVG无法转成pixleMap,请加上<?xml version="1.0" encoding="UTF-8"?>

分享
微博
QQ
微信
回复
4天前
相关问题
HarmonyOS如何将Component转换PixelMap
627浏览 • 1回复 待解决
HarmonyOS 网络图片如何转换PixelMap
168浏览 • 1回复 待解决
HarmonyOS 自定义View怎么转换PixelMap
151浏览 • 1回复 待解决
如何实现PixelMap和base64的相互转换
2100浏览 • 1回复 待解决
HarmonyOS svg图标
221浏览 • 1回复 待解决
如何将app.media.app_icon,转换PixelMap
2292浏览 • 1回复 待解决
HarmonyOS RNOH问题反馈 - SVG组件
158浏览 • 1回复 待解决
PixelMap类型怎么转换成Base64字符串
881浏览 • 1回复 待解决
HarmonyOS pixelMap
180浏览 • 1回复 待解决
HarmonyOS 如何在Canvas中直接绘制SVG
170浏览 • 1回复 待解决
HarmonyOS Image如何加载svg
171浏览 • 1回复 待解决
HarmonyOS svg图片尺寸
437浏览 • 1回复 待解决
HarmonyOS 是否支持SVG动画
182浏览 • 1回复 待解决