HarmonyOS 鸿蒙Next记录工具类【1】将一个base64编码的图片字符串写入到设备的文件系统中,并返回图片的沙箱路径URI。【2】读取指定路径的图片文件,将其转换为像素地图(PixelMap),并返回这个像素地图对象。
HarmonyOS 鸿蒙Next记录工具类【1】将一个base64编码的图片字符串写入到设备的文件系统中,并返回图片的沙箱路径URI。【2】读取指定路径的图片文件,将其转换为像素地图(PixelMap),并返回这个像素地图对象。
import { buffer } from ‘@kit.ArkTS’;
import { fileIo, fileUri } from ‘@kit.CoreFileKit’;
import image from ‘@ohos.multimedia.image’;
import fs from ‘@ohos.file.fs’;
import { common } from ‘@kit.AbilityKit’;
interface objType {
uri: string
path: string
}
export class FileOperate {
// data为需要转换的base64字符串,返回沙箱路径uri
static async writeFile(data: string): Promise<string> {
let uri = ‘’
let filesDir = getContext().filesDir;
console.info(filesDir:${filesDir}
)
try {
let filePath = filesDir + “/1.png”;
uri = fileUri.getUriFromPath(filePath);
let file = fileIo.openSync(filePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE);
console.info("file fd: " + file.fd);
const reg = new RegExp(“data:image/\w+;base64,”)
const base64 = data.replace(reg, “”);
console.log(“base64flag”, base64)
const dataBuffer = buffer.from(base64, ‘base64’)
await fileIo.writeSync(file.fd, dataBuffer.buffer);
fileIo.closeSync(file);
console.log(<span class="hljs-string"><span class="hljs-string">"base64 写入成功 uri-->"</span></span>, uri)
} <span class="hljs-keyword"><span class="hljs-keyword">catch</span></span> (<span class="hljs-built_in"><span class="hljs-built_in">Error</span></span>) {
console.log(<span class="hljs-string"><span class="hljs-string">'Error.code'</span></span>, <span class="hljs-string"><span class="hljs-string">'----->👉'</span></span>, <span class="hljs-built_in"><span class="hljs-built_in">JSON</span></span>.stringify(<span class="hljs-built_in"><span class="hljs-built_in">Error</span></span>));
}
<span class="hljs-comment"><span class="hljs-comment">//uri:file://com.midea.weexwebsdkdemo/data/storage/el2/base/haps/entry/files/1.png</span></span>
<span class="hljs-keyword"><span class="hljs-keyword">return</span></span> uri
}
static async fileChangePixelMap(path: string) {
try {
<span class="hljs-comment"><span class="hljs-comment">// 打开文件读取流</span></span>
<span class="hljs-keyword"><span class="hljs-keyword">let</span></span> file = fs.openSync(path, fs.OpenMode.READ_ONLY);
<span class="hljs-comment"><span class="hljs-comment">// 获取当前上下文</span></span>
<span class="hljs-keyword"><span class="hljs-keyword">let</span></span> context = getContext() as common.UIAbilityContext;
<span class="hljs-comment"><span class="hljs-comment">// 新建一个保存裁剪后图片的路径</span></span>
<span class="hljs-keyword"><span class="hljs-keyword">let</span></span> newPath = context.filesDir + <span class="hljs-string"><span class="hljs-string">'/test'</span></span> + <span class="hljs-keyword"><span class="hljs-keyword">new</span></span> <span class="hljs-built_in"><span class="hljs-built_in">Date</span></span>().getTime() + <span class="hljs-string"><span class="hljs-string">'.jpg'</span></span>;
<span class="hljs-comment"><span class="hljs-comment">// 复制图片到新的路径</span></span>
fs.copyFileSync(file.fd, newPath);
<span class="hljs-comment"><span class="hljs-comment">// 关闭文件读取流</span></span>
fs.closeSync(file);
<span class="hljs-comment"><span class="hljs-comment">// 创建图片源对象</span></span>
<span class="hljs-keyword"><span class="hljs-keyword">const</span></span> imageSource: image.ImageSource = image.createImageSource(newPath);
console.log(<span class="hljs-string"><span class="hljs-string">'imageSource🥳'</span></span>, <span class="hljs-string"><span class="hljs-string">'----->👉'</span></span>, <span class="hljs-built_in"><span class="hljs-built_in">JSON</span></span>.stringify(imageSource));
<span class="hljs-comment"><span class="hljs-comment">// 图片解码选项</span></span>
<span class="hljs-keyword"><span class="hljs-keyword">let</span></span> decodingOptions: image.DecodingOptions = {
editable: <span class="hljs-literal"><span class="hljs-literal">true</span></span>,
desiredPixelFormat: <span class="hljs-number"><span class="hljs-number">3</span></span>,
};
<span class="hljs-comment"><span class="hljs-comment">// 创建像素地图</span></span>
<span class="hljs-keyword"><span class="hljs-keyword">let</span></span> mPixelMap: image.PixelMap = await imageSource.createPixelMap(decodingOptions);
<span class="hljs-comment"><span class="hljs-comment">// 获取图片信息</span></span>
<span class="hljs-keyword"><span class="hljs-keyword">let</span></span> mImageInfo: image.ImageInfo = await mPixelMap.getImageInfo();
console.log(<span class="hljs-string"><span class="hljs-string">'mImageInfo🥳'</span></span>, <span class="hljs-string"><span class="hljs-string">'----->👉'</span></span>, <span class="hljs-built_in"><span class="hljs-built_in">JSON</span></span>.stringify(mImageInfo));
<span class="hljs-keyword"><span class="hljs-keyword">return</span></span> mPixelMap
} <span class="hljs-keyword"><span class="hljs-keyword">catch</span></span> (e) {
console.error(<span class="hljs-string"><span class="hljs-string">'imgChange🥳'</span></span>, <span class="hljs-built_in"><span class="hljs-built_in">JSON</span></span>.stringify(e));
<span class="hljs-keyword"><span class="hljs-keyword">return</span></span> <span class="hljs-literal"><span class="hljs-literal">undefined</span></span>
}
}
}
@Entry
@Component
struct Page41 {
@State mPixelMap: image.PixelMap | undefined = undefined
@State uri: string = “”
@State base64Str: string =
‘data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAMAAABHPGVmAAADAFBMVEX///8BAgIDAwP9+/v+/v02ODwCBAUoKy4iJik7PUL+/P00NTkgIycoLDAZGx8mKi0sLzIkKCwdHyImJysnKS0FBAX8+/0bHB8FBgb89vMHCQokJikvMDT69vQ5Oj4MDQ8rLTEPERMFBgkdISUxMzgxMjUkNWsKCwwTFRciJCYfISUrLC8XGBsaHSIXGR0REhX6+vqRdX/+/f+OdH0nOG4HCg8sMTUbHyTo5uwKDhP59/n89vXs6u7j4eH39vXn4+Pb2dnHxsfv7e3q5+YrO29YX2ciM2YTFxvx8PDn5efMzNLd2N/g3dzPz9CqrK7V0dgPDg/08/Tj3ePNycqOdn44ODj08/r88/Hk4efW1tX08vHb1NjV0dIXFhjx7vTp6fHt6ekxP3NFQkO5urs0Qnjs7fT58/Lw6/DAub2GgYfEvMLUzM++v763srqrpKwbGxzKxc6wrq1+fH+JcXn49v3v7/qcnaFPWGYjMmBISE0LER3y8fjW1+CEbnYsPHTDwsSmp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GuWT1JG5pC67oMd/SlL1+kOR8851h9RzlWPqkJbBkKp0LqyhKBgSpkqS56gSHMofXaQIE6pTHcG0ulINr0bPD3Uf74gb7VaaZriFmmVtZjKbAlRaKMDkIGQxGogOFWLyIU0x00dQK7oA8NDDSA61OsGz7b3L8wjiKQIKjrERMAlgyDVvyFupNq8CFSq+lQuIb8O9t+/yfX/RaQcEsHnM+/f3m6R0laKSKgqrLSjP+Ug9Bt1kOLeW0+v0QAAAABJRU5ErkJggg==’
build() {
Column() {
Button(‘测试 writeFile’).onClick(async () => {
this.uri = await FileOperate.writeFile(this.base64Str)
})
Button(‘测试 fileChangePixelMap’).onClick(async () => {
this.mPixelMap = await FileOperate.fileChangePixelMap(this.uri)
})
Image(this.mPixelMap).width(‘200lpx’)
}
.height(‘100%’)
.width(‘100%’)
}
}
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>
关于HarmonyOS 鸿蒙Next记录工具类【1】将一个base64编码的图片字符串写入到设备的文件系统中,并返回图片的沙箱路径URI。【2】读取指定路径的图片文件,将其转换为像素地图(PixelMap),并返回这个像素地图对象。的问题,您也可以访问:https://www.itying.com/category-93-b0.html 联系官网客服。
大佬,在模拟器上面可以测试到这一步吗?
可以,上面的截图就是在模拟器上截的。