【HarmonyOS NEXT】实现保存base64图片到图库

上篇文章介绍了HarmonyOS NEXT如何保存base64文件到download目录下,本次介绍如何保存base64图片到图库,网络图片保存方式大同小异,先下载图片,然后再保存

phAccessHelper.showAssetsCreationDialog

参考官方文档’

@ohos.file.photoAccessHelper (相册管理模块)-ArkTS API-Media Library Kit(媒体文件管理服务)-媒体 - 华为HarmonyOS开发者 (huawei.com)

完整代码如下

//模拟数据param ="{\"dataBase64\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA4QAAACiCAYAAAAZUwONAAAAAXNSR0IArs4c6QAAHWFJREFUeF7t3QusHFX9B/CDQdKqYCwiggELpjFS8IGaohXaYgCDBnxUbCUVovUFCKQxGvFZXokYIygGBTWFGGpiqtCYCohiiVURREUoj6YRW6BYKU2lAq0x/ec3cfY/d9m9u927OzO98znJTXt3Z+ac85lTki/nzJy9du3atSspBAgQIECAAAECBAgQINA4gb0Ewsbdcx0mQIAAAQIECBAgQIBAJiAQGggECBAgQIAAAQIECBBoqIBA2NAbr9sECBAgQIAAAQIECBAQCI0BAgQIECBAgAABAgQINFRAIGzojddtAgQIECBAgAABAgQICITGAAECBAgQIECAAAECBBoqIBA29MbrNgECBAgQIECAAAECBARCY4AAAQIECBAgQIAAAQINFRAIG3rjdZsAAQIECBAgQIAAAQICoTFAgAABAgQIECBAgACBhgoIhA298bpNgAABAgQIECBAgAABgdAYIECAAAECBAgQIECAQEMFBMKG3njdJkCAAAECBAgQIECAgEBoDBAgQIAAAQIECBAgQKChAgJhQ2+8bhMgQIAAAQIECBAgQEAgNAYIECBAgAABAgQIECDQUAGBsKE3XrcJECBAgAABAgQIECAgEBoDBAgQIECAAAECBAgQaKiAQNjQG6/bBAgQIECAAAECBAgQEAiNAQIECBAgQIAAAQIECDRUQCBs6I3XbQIECBAgQIAAAQIECAiExgABAgQIECBAgAABAgQaKiAQNvTG6zYBAgQIECBAgAABAgQEQmOAAAECBAgQIECAAAECDRUQCBt643WbAAECBAgQIECAAAECAq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HtUTPOeec9K1vfWuMcATMe++9N/vsyCOPzMLmXnvtVdO7oFkECBAgQIAAAQIEJreAQFjT+1tlILzsssvSZz/72ZZMPPc3f/781u8f+9jHsucKo8Ry0Vg2GuXWW28d8zzhxRdfnD1DWCzvfOc706pVq1of/fOf/0wvfelLa3oXNIsAAQIECBAgQIDA5BYQCGt6f/sJhL/+9a/TvHnz+u7B448/3nqeb7yTHnvssezZvtg6IkrMEl599dXZ20Ej9L3jHe/IPv/EJz6RzQDmW0hcd911rXAY319++eXpvPPOG1PV6aefnq6//vrWZ3/6059SLDNVCBAgQIAAAQIECBAoX0AgLN+8rxr7CYS/+93v0sc//vG+rhcHxX6CBxxwQF/HR9iM2bynn366dfwb3/jG9Mc//jEddNBB2bN/MTP4vOc9r/V9hMNzzz239Xu8YCZCY7EUZxfj86gn9jVUCBAgQIAAAQIECBAoX0AgLN+8rxr7CYR9XWgCB/31r3/N9iLMt5DILxXPDX71q19NM2bMGHP19qWmMav40Y9+dMwx8QbSCIp5+fnPf96acZxAU51KgAABAgQIECBAgMAAAgLhAGhlnFJ1IHzmmWey4PaVr3yltTl9sd+xHcU3vvGNLPDlL4XpJxB+8pOfTN/5zndal7rpppvSSSedVAapOggQIECAAAECBAgQaBMQCGs6JKoMhLHvYCwHzV/+EnsOxrN/V155Zfra1742RixmCj/zmc9kn8X3seF8XjotGY0A+b3vfa91TGxLEdtTKAQIECBAgAABAgQIlC8gEJZvPm6N8UxdlK1bt6b7778/xV593cooniHctWtXtkz0hz/8YVZt7DcYf89nAdesWZM+8IEPpEcffbTVrPzFMHHcokWLWp93eqlMXC/2McyLzelrNgA1hwABAgQIECBAoFECAmENbncsy4yZsjwMRpMidMWbPscLhKN4y2i8NCY2m89Lp5e+3Hjjjend735365iYNfz0pz+dfvWrX6W3v/3trc8vuuii9IUvfGGM8Mknn5ziucG8xB6HL3nJS2pwFzSBAAECBAgQIECAQPMEBMIK73mEraVLl44JgsXmHH/88dmbQcsssSF9bEyflw0bNqRDDjlkTBN27NiRpk2b1noD6dlnn50tF924cWM69NBDW8fmnxdPnjlzZlq7dm32UWw3EbOLCgECBAgQIECAAAEC1QgIhNW4Z7XmyzC7NSG2ffjZz35WagtXrlyZTj311FadDzzwQHr1q189pg3//e9/0/7775+2bduWfR6zmLENRZQ3v/nN6a677sr+Hs8GxsxnXrZv357taZiXL37xi+nCCy8stX8qI0CAAAECBAgQIEDg/wUEwopGQywTjdnB8cptt92W5s6dW2oL//a3v6XDDz+8VWfMGMby1WKJGb6Y6ctLLCE95ZRTsl+vueaaFHsN5uXxxx9PBx54YPbr7bffPmbPwfvuuy8dccQRpfZPZQQIECBAgAABAgQICISVj4Fes4MRBCMQVlHiTaGxBDTKUUcdlT3z94pXvCL7/d///ndavHhxiqAY5dhjj0233npr2meffbLfYxZw3rx5rVnCmAWM4Ltz585sKWq8PTXKkiVL0te//vUquqdOAgQIECBAgAABAgT+J2CGsIKh0OtlMFWGwTz0xfN/1157baYTzwWedtppacqUKVk4jBfPRDnhhBPSsmXL0sEHHzxG8cEHH0zz589P9957b/b52972tmx5aWx0HyWCYWw9EXsZKgQIECBAgAABAgQIVCcgEFZk323J6Je//OVsM/iqS2w/Ec//xYzeb3/72xRLSaNMnz49zZo1K73rXe/KAuHee+/dsanx9tDrr78+3XDDDdlLZCL8veENb0gLFizInlHsdl7V/VY/AQIECBAgQIAAgSYJCIQV3e2YJYyf/KUrc+bMyZ4XLPuZwYq6r1oCBAgQIECAAAECBGogIBDW4CZoAgECBAgQIECAAAECBKoQEAirUFcnAQIECBAgQIAAAQIEaiAgENbgJmgCAQIECBAgQIAAAQIEqhAQCKtQVycBAgQIECBAgAABAgRqICAQ1uAmaAIBAgQIECBAgAABAgSqEBAIq1BXJwECBAgQIECAAAECBGogUOtAGPvx1WFPvhrcJ00gQIAAAQIECBAgQIDA0AVqGwjnzZuX7dNXl43ahy7vggQIECBAgAABAgQIEKhYoJaBMGYFly5d2qIRCiseJaonQIAAAQIECBAgQGBSCtQuEMasYMwOtp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gQIECAAAGB0BggQIAAAQIECBAgQIBAQwUEwobeeN0mQIAAAQIECBAgQICAQGgMECBAgAABAgQIECBAoKECAmFDb7xuEyBAgAABAgQIECBAQCA0BggQIECAAAECBAgQINBQAYGwoTdetwkQIECAAAECBAgQICAQGgMECBAgQIAAAQIECBBoqIBA2NAbr9sECBAgQIAAAQIECBAQCI0BAgQIECBAgAABAgQINFRAIGzojddtAgQIECBAgAABAgQI/B8WlZTPhnLNzQAAAABJRU5ErkJggg==\",\"fileType\":\"png\",\"fileName\":\"\"}"if (StringUtils.isStrNotBlank(param)) {const h5CallBackBean: H5CallBackBean | null = JSONUtil.jsonToBean<H5CallBackBean>(H5CallBackBean, param)
//保存图片let context = getContext(this);let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context);const fileBase64 = h5CallBackBean.dataBase64if (StringUtils.isStrNotBlank(fileBase64)) {const base64: string = fileBase64.split(",")[1]let applicationContext = getContext().getApplicationContext()const numTemp: number = DateUtil.getTodayTime()let filePath = applicationContext.filesDir + '/' + numTemp + "." + h5CallBackBean.fileTypeif (UiUtils.saveBase64File(base64, filePath)) {try {// 获取需要保存到媒体库的位于应用沙箱的图片/视频urilet srcFileUris: Array<string> = [fileUri.getUriFromPath(filePath)];let photoCreationConfigs: Array<photoAccessHelper.PhotoCreationConfig> = [{fileNameExtension: 'jpg',photoType: photoAccessHelper.PhotoType.IMAGE,subtype: photoAccessHelper.PhotoSubtype.DEFAULT, // 可选}];let desFileUris: Array<string> =await phAccessHelper.showAssetsCreationDialog(srcFileUris, photoCreationConfigs);console.info('showAssetsCreationDialog success, data is ' + desFileUris);if (desFileUris.length > 0) {FileUtil.copyFileSync(filePath,new fileUri.FileUri(desFileUris[0]).path)try {console.log(`context.fileDir ===> ${context.filesDir}`)let srcFile: fs.File = fs.openSync(fileUri.getUriFromPath(filePath), fs.OpenMode.READ_ONLY);let targetFile: fs.File = await fs.open(desFileUris[0], fs.OpenMode.READ_WRITE);let bufSize = 14096;let readSize = 0;let buf = new ArrayBuffer(bufSize);let readOptions: ReadOptions = { offset: readSize, length: bufSize };let readLen = fs.readSync(srcFile.fd, buf, readOptions);while (readLen > 0) {readSize += readLen;fs.writeSync(targetFile.fd, buf, { length: readLen });readOptions.offset = readSize;readLen = fs.readSync(srcFile.fd, buf, readOptions);}fs.closeSync(srcFile);fs.closeSync(targetFile);ToastUtil.showToast("保存成功")if (FileUtil.accessSync(filePath)) {FileUtil.unlink(filePath)}} catch (error) {console.error(`createAssetByIo :: error , msg is ${error} `);}} else {ToastUtil.showToast("您拒绝了保存图片")}} catch (err) {console.error('showAssetsCreationDialog failed, errCode is ' + err.code + ', errMsg is ' + err.message);}} else {ToastUtil.showToast("保存失败,请稍后重试")}}}}

其中用到的第三方依赖和上篇文章一致

参考:HarmonyNext保存Base64文件到Download下-CSDN博客

效果如下

【其它问题】
关于授权窗,没显示图片缩略图的问题,官方给的答复是下载最新版本的IDE

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/453302.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

利用透视变换实现文档矫正功能

透视变换是将成像投影到一个新的平面上&#xff0c;也称作投影映射。OpenCV通过函数cv2.getPerspectiveTransorm(pos1,pos2)构造矩阵M&#xff0c;其中pos1和pos2分别表示变换前后4个点的对应位置。得到M后再通过函数cv2.warpPerspective(src,M,(cols,rows))进行透视变换。 函数…

Threejs 实现3D 地图(02)创建3d 地图

"d3": "^7.9.0", "three": "^0.169.0", "vue": "^3.5.10" 地图数据来源&#xff1a; DataV.GeoAtlas地理小工具系列 <script setup> import {onMounted, ref} from vue import * as THREE from three im…

空间单细胞转录组cell2location分析流程学习

Cell2location 是一个用于空间转录组学数据分析的工具。它是一个基于贝叶斯统计模型的Python包&#xff0c;旨在利用空间转录组数据和单细胞转录组数据来进行细胞类型的空间解构。通过将单细胞转录组数据中的细胞类型信息投射到空间转录组数据中&#xff0c;Cell2location 可以…

如何应对 Android 面试官 -> ANR 如何优化?线上 ANR 如何监控?

前言 本章主要围绕 ANR 如何监控以及优化&#xff1b; 基本概念 ANR(Android Not Responding) 是指应用程序未响应&#xff0c;Android 系统对于一些事件需要在一定的时间范围内完成&#xff0c;如果超过预订时间未能得到有效响应或者响应时间过长&#xff0c;都会造成 ANR。 …

SAP_MM模块-设置业务合作伙伴类型字段必输(多种方案)

一、业务背景 公司需要把供应商增加一个细分的维度&#xff0c;并且要求该字段设置为必输&#xff0c;防止用户新增供应商时忘记维护。这里给用户找了一个分类的字段&#xff1a;业务合作伙伴类型&#xff0c;本文主要讲解如何设置该字段设置为必填&#xff1b; 注意&#xff…

[笔记] 关于CreateProcessWithLogonW函数创建进程

函数介绍 https://learn.microsoft.com/zh-cn/windows/win32/api/winbase/nf-winbase-createprocesswithlogonw BOOL CreateProcessWithLogonW([in] LPCWSTR lpUsername,[in, optional] LPCWSTR lpDomain,[in] …

【MySQL】表的约束、基本查询、内置函数

目录 1. 表的约束1.1 空属性1.2 默认值1.3 列描述1.4 zerofill1.5 主键1.6 自增长1.7 唯一键1.8 外键 2. 基本查询2.1 表的增删改查2.1.1 插入数据2.1.2 插入否则更新2.1.3 替换插入 2.2 Retrieve2.2.1 select ----- 查询2.2.2 where ----- 筛选2.2.3 order by ----- 结果排序2…

C++11——基础新增特性

目录 C11介绍统一的列表初始化对内置类型initializer_list 声明autodecltypenullptr 范围for容器新增接口emplace容器的新方法 C的前身是“C with Classes”&#xff0c; 最早于 1979年由 祖师爷Bjarne Stroustrup&#xff08;本贾尼斯特劳斯特鲁普&#xff09; 在贝尔实验室…

#HarmonyOS:页面和自定义组件生命周期

页面生命周期 即被Entry装饰的组件生命周期 onPageShow&#xff1a;页面每次显示时触发一次&#xff0c;包括路由过程、应用进入前台等场景。onPageHide: 页面每次隐藏时触发一次&#xff0c;包括路由过程、应用进入后台等场景。onBackPress: 当用户点击返回按钮是触发 组件…

成都睿明智科技有限公司解锁抖音电商新蓝海

在这个短视频风靡的时代&#xff0c;抖音已不仅仅是一个娱乐平台&#xff0c;它更是商家们竞相追逐的电商新战场。成都睿明智科技有限公司&#xff0c;作为抖音电商服务领域的佼佼者&#xff0c;正以敏锐的洞察力和专业的服务&#xff0c;助力众多品牌在这片蓝海中乘风破浪&…

RHCE-多IP访问网站

关闭防火墙 [rootlocalhost ~]# systemctl stop firewalld [rootlocalhost ~]# setenforce 0下载nginx工具 [rootlocalhost ~]# yum install nginx Updating Subscription Management repositories. Unable to read consumer identityThis system is not registered with an …

面对AI算力需求激增,如何守护数据中心机房安全?

随着人工智能&#xff08;AI&#xff09;技术飞速发展&#xff0c;AI算力需求呈现爆发式增长&#xff0c;导致对数据设备电力的需求指数级攀升。这给数据中心带来前所未有的挑战和机遇&#xff0c;从提供稳定的电力供应、优化高密度的部署&#xff0c;到数据安全的隐私保护&…

【unity小技巧】Unity6 LTS版本安装和一些修改和新功能使用介绍

文章目录 前言安装新功能变化1、官方推荐使用inputsystem进行输入控制2、修复了InputSystem命名错误导致listen被遮挡的bug3、自带去除unity启动画面logo功能4、unity官方的behavior行为树插件5、linearVelocity代替过时的velocity方法待续 完结 前言 2024/10/17其实unity就已…

前端拦截302重定向

背景: 根据业务场景需要拦截302做后续的逻辑处理 尝试一: : axios拦截 、、、、、async created() {// 获取302请求返回的location后手动修改video的src路径let targetSrc;try {await axios.get(this.video).then((res) > {const { headers, status } res;const { locat…

Spring Cloud 解决了哪些问题?

大家好&#xff0c;我是锋哥。今天分享关于【Spring Cloud 解决了哪些问题&#xff1f;】面试题&#xff1f;希望对大家有帮助&#xff1b; Spring Cloud 解决了哪些问题&#xff1f; 1000道 互联网大厂Java工程师 精选面试题-Java资源分享网 Spring Cloud 是一个为构建分布式…

如何删除Maven

1.找到Maven安装路径 方法一&#xff1a; 可以直接在文件资源管理器里面选中“此电脑”然后右上角搜“apache-maven”&#xff0c;这个过程可能长达几分钟甚至更久 方法二&#xff1a; 这里推荐一个名叫“Everything”的软件&#xff0c;能够快速的查找到需要的文件 2.找到本…

每日一道算法题(Leetcode 20)

Whats past is prologue. 凡是过去&#xff0c;皆为序章。 题目 分析 1. 我们可以用栈的结构来解决这道题。 2. 我们使用while循环&#xff0c;每次读取字符串中一个元素进行操作&#xff0c;直到最后读取到 \0为止。 3. 如果遇见 (, [ ,{ 这三种左括号&#xff0c;则把该左…

【AIGC】AI如何匹配RAG知识库:关键词搜索

关键词搜索 引言jieba库简介TF-IDF简介实践例子用jieba库提取关键词计算TF-IDF计算文档和查询相似度结果完整代码&#xff1a; 总结 引言 RAG作为减少模型幻觉和让模型分析、回答私域相关知识最简单高效的方式&#xff0c;我们除了使用之外可以尝试了解其是如何实现的。在实现…

写一个自动采集地球前30行业的小程序

创建一个自动采集地球前30行业信息的小程序可以使用Python和一些常用的库&#xff0c;如BeautifulSoup和Requests。以下是一个基本示例&#xff0c;展示如何从网页上抓取行业信息&#xff1a; 环境准备 安装Python&#xff1a;确保你的计算机上已安装Python。安装库&#xff…

电影评论网站开发:Spring Boot技术指南

3系统分析 3.1可行性分析 通过对本电影评论网站实行的目的初步调查和分析&#xff0c;提出可行性方案并对其一一进行论证。我们在这里主要从技术可行性、经济可行性、操作可行性等方面进行分析。 3.1.1技术可行性 本电影评论网站采用SSM框架&#xff0c;JAVA作为开发语言&#…