HarmonyOS 如何将base64数据转换为图片

HarmonyOS 如何将base64数据转换为图片

HarmonyOS
2024-08-22 19:17:04
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
superinsect

参考如下代码:

let that = new util.Base64Helper(); 
let base64 = 'iVBORw0KGgoAAAANSUhEUgAAAB4AAAAtCAMAAAxxxxxxxxaXE2QU03QE02QU48PEs0Q0s2QU42Qk43QE43QU03QU04P043QE43QVA3QU7fFG+6AAAADnRSTlMAu3fuESKPVd1mzESqM0jcJEgAAACOSURBVHjatZBJEsAgCARV3BP5/3Oj3mdIZZlrF9CMs+Jx2sSKE/7FIEMmxxxTuisS8aYRWTykA060xDtKipVelhLYiGRU+6WhJdHai1QK+6X6ZeFXYt9rBEOhzosCaqnfHPtO2TfpV0JXOxgXB/v5t7q0PZ1CN66I2+D3460q/lodkgpdjibeNm/fVtLk4YEK1O5uSkxxxxlFTkSuQmCC'; 
let result:Uint8Array = that.decodeSync(base64, util.Type.MIME); 
let buf:ArrayBuffer = result.buffer as ArrayBuffer 
const context: Context = getContext(this); 
const path1: string = context.cacheDir + "/pixel_map1168.jpg"; 
let file = fs.openSync(path1, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); 
 
fs.write(file.fd, buf).then(async (writeLen) => { 
 
  console.info("write data to file succeed and size is:" + writeLen); 
  fs.closeSync(file); 
}).catch((err: BusinessError) => { 
  console.info("write data to file failed with error message: " + err.message + ", error code: " + err.code); 
}); 
 
})
分享
微博
QQ
微信
回复
2024-08-23 17:37:16
相关问题
HarmonyOS如何将图片Base64
695浏览 • 1回复 待解决
如何base64转换图片
10048浏览 • 2回复 待解决
如何将图片base64字符串转PixelMap?
428浏览 • 1回复 待解决
如何将PixelMap转图片base64字符串?
330浏览 • 1回复 待解决
HarmonyOS Image如何显示base64图片
232浏览 • 1回复 待解决
HarmonyOS 图片进行base64编码报错
420浏览 • 1回复 待解决
如何实现PixelMap和base64的相互转换
1550浏览 • 1回复 待解决
怎么把PixelMap图片BASE64
9179浏览 • 1回复 待解决
HarmonyOS base64编码问题
248浏览 • 1回复 待解决
js canvas转base64编码图片不全
10527浏览 • 1回复 待解决
HarmonyOS base64解码报错
553浏览 • 1回复 待解决
base64字符串保存为图片的方法
528浏览 • 1回复 待解决