HarmonyOS 鸿蒙Next Pixmap保存到本地文件如何实现?
HarmonyOS 鸿蒙Next Pixmap保存到本地文件如何实现?
找HarmonyOS工作还需要会Flutter的哦,有需要Flutter教程的可以学学大地老师的教程,很不错,B站免费学的哦:https://www.bilibili.com/video/BV1S4411E7LY/?p=17
2 回复
Pixmap保存到本地文件如何实现?
更多关于HarmonyOS 鸿蒙Next Pixmap保存到本地文件如何实现?的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
static async savePixelMap(pixelMap: image.PixelMap, path: string, name: string,
format: string = 'image/png'): Promise<string> {
try {
if (!fs.accessSync(path)) {
fs.mkdirSync(path, true); //如果文件夹不存在就创建
}
let filePath = path + "/" + name;
let file = fs.openSync(path, fs.OpenMode.READ_WRITE);
let packOpts: image.PackingOption = { format: format, quality: 100 }
<span class="hljs-keyword"><span class="hljs-keyword">const</span></span> imagePacker: image.ImagePacker = image.createImagePacker();
await imagePacker.packToFile(pixelMap, file.fd, packOpts).finally(() => {
imagePacker.release(); <span class="hljs-comment"><span class="hljs-comment">//释放</span></span>
});
fs.closeSync(file.fd);<span class="hljs-comment"><span class="hljs-comment">//关闭文件</span></span>
<span class="hljs-keyword"><span class="hljs-keyword">return</span></span> filePath;
} catch (err) {
let error = err as BusinessError;
console.log(ImageUtil-savePixelMap-异常 ~ code: ${error.code} -·- message: ${error.message}
);
return ‘’;
}
}
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>