把一个base64图片 保存到鸿蒙手机 相册中怎么实现呢?
下面有2中方法
方案一:可以通过安全控件「保存控件(SaveButton)」实现。该控件对应媒体库写入特权。应用集成保存控件后,用户点击该控件,应用会获取10秒内单次访问媒体库特权接口的授权。
参考代码:
import { photoAccessHelper } from '@kit.MediaLibraryKit';
import fs from '@ohos.file.fs';
import { http } from '@kit.NetworkKit';
import { promptAction } from '@kit.ArkUI';
/** * 参考资料: * https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/photoaccesshelper-resource-guidelines-0000001774280306-V5#ZH-CN_TOPIC_0000001881258417__使用安全控件创建媒体资源 */
@Entry
@Component
struct Index {
@State message: string = 'Hello World'
@State saveButtonOptions: SaveButtonOptions = {
icon: SaveIconStyle.FULL_FILLED,
text: SaveDescription.SAVE_IMAGE,
buttonType: ButtonType.Capsule
}
// 设置安全控件按钮属性
build() {
Row() {
Column() {
Text(this.message).fontSize(50).fontWeight(FontWeight.Bold)
SaveButton(this.saveButtonOptions)// 创建安全控件按钮
.onClick(async (event, res

最低0.47元/天 解锁文章
1063

被折叠的 条评论
为什么被折叠?



