当前位置: 首页 > news >正文

宝鸡做网站公司宁波seo推广服务电话

宝鸡做网站公司,宁波seo推广服务电话,响应式网站是做列表,网络公司哪个效果好【HarmonyOS】 鸿蒙保存图片或视频到相册 前言 鸿蒙中保存图片或者视频,或者其他媒体文件到设备的媒体库,可以是相册,也可以是文件管理等。共有两种方式: 需要应用申请受限权限,获取文件读写的权限(调用…

【HarmonyOS】 鸿蒙保存图片或视频到相册

前言

鸿蒙中保存图片或者视频,或者其他媒体文件到设备的媒体库,可以是相册,也可以是文件管理等。共有两种方式:

  1. 需要应用申请受限权限,获取文件读写的权限(调用需要ohos.permission.READ_IMAGEVIDEO和ohos.permission.WRITE_IMAGEVIDEO的权限),这样就可以将媒体资源(图片or视频or等等)保存到媒体库。
  2. 通过安全控件,用户触发后表示同意,可以临时授权给应用就行保存处理。

关于第二种安全控件,又分为saveButton保存按钮showAssetsCreationDialog授权弹框两种形式。前者的按钮样式不能自定义,所以后者以弹框的形式,让用户操作,触发入口的样式,应用就可以自定义了。后者算是前者的一种替代补充。

一、保存图片和视频授权示例

需要申请"ohos.permission.READ_IMAGEVIDEO"和"ohos.permission.WRITE_IMAGEVIDEO"权限。该权限是管制权限,需要你的应用去通过场景申请【申请使用受限权限】

配置权限READ_IMAGEVIDEO,WRITE_IMAGEVIDEO

"requestPermissions": [{"name": "ohos.permission.READ_IMAGEVIDEO","usedScene": {"abilities": ["EntryAbility"],"when": "inuse"},"reason": "$string:CAMERA"},{"name": "ohos.permission.WRITE_IMAGEVIDEO","usedScene": {"abilities": ["EntryAbility"],"when": "inuse"},"reason": "$string:CAMERA"}
]

向用户申请权限

//  创建申请权限明细async reqPermissionsFromUser(): Promise<number[]> {let context = getContext() as common.UIAbilityContext;let atManager = abilityAccessCtrl.createAtManager();let grantStatus = await atManager.requestPermissionsFromUser(context, ['ohos.permission.READ_IMAGEVIDEO','ohos.permission.WRITE_IMAGEVIDEO']);return grantStatus.authResults;}// 用户申请权限async requestPermission() {let grantStatus = await this.reqPermissionsFromUser();for (let i = 0; i < grantStatus.length; i++) {if (grantStatus[i] === 0) {// 用户授权,可以继续访问目标操作}}}

保存图片到媒体库

public async savePicture(buffer: ArrayBuffer): Promise<void> {let helper : photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(getContext(this) as common.UIAbilityContext);let options: photoAccessHelper.CreateOptions = {title: Date.now().toString()};let photoUri: string = await helper.createAsset(photoAccessHelper.PhotoType.IMAGE, 'jpg', options);console.info(photoUri)// createAsset的调用需要ohos.permission.READ_IMAGEVIDEO和ohos.permission.WRITE_IMAGEVIDEO的权限let file: fs.File = fs.openSync(photoUri, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);await fs.write(file.fd, buffer);fs.closeSync(file);
}

二、saveButton示例

import { photoAccessHelper } from '@kit.MediaLibraryKit';

struct saveButtonExample {saveButtonOptions: SaveButtonOptions = {icon: SaveIconStyle.FULL_FILLED,text: SaveDescription.SAVE_IMAGE,buttonType: ButtonType.Capsule} // 设置安全控件按钮属性build() {Row() {Column() {SaveButton(this.saveButtonOptions) // 创建安全控件按钮.onClick(async (event, result: SaveButtonOnClickResult) => {if (result == SaveButtonOnClickResult.SUCCESS) {try {let context = getContext();let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context);// 需要确保fileUri对应的资源存在let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg';let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createImageAssetRequest(context, fileUri);await phAccessHelper.applyChanges(assetChangeRequest);console.info('createAsset successfully, uri: ' + assetChangeRequest.getAsset().uri);} catch (err) {console.error(`create asset failed with error: ${err.code}, ${err.message}`);}} else {console.error('SaveButtonOnClickResult create asset failed');}})}.width('100%')}.height('100%')}
}

三、 showAssetsCreationDialog示例

import { photoAccessHelper } from '@kit.MediaLibraryKit';
import { fileIo } from '@kit.CoreFileKit';let context = getContext(this);
let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context);async function showAssetsCreationDialogExample() {try {// 指定待保存到媒体库的位于应用沙箱的图片urilet srcFileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg';let srcFileUris: Array<string> = [srcFileUri];// 指定待保存照片的创建选项,包括文件后缀和照片类型,标题和照片子类型可选let photoCreationConfigs: Array<photoAccessHelper.PhotoCreationConfig> = [{title: 'test', // 可选fileNameExtension: 'jpg',photoType: photoAccessHelper.PhotoType.IMAGE,subtype: photoAccessHelper.PhotoSubtype.DEFAULT, // 可选}];// 基于弹窗授权的方式获取媒体库的目标urilet desFileUris: Array<string> = await phAccessHelper.showAssetsCreationDialog(srcFileUris, photoCreationConfigs);// 将来源于应用沙箱的照片内容写入媒体库的目标urilet desFile: fileIo.File = await fileIo.open(desFileUris[0], fileIo.OpenMode.WRITE_ONLY);let srcFile: fileIo.File = await fileIo.open(srcFileUri, fileIo.OpenMode.READ_ONLY);await fileIo.copyFile(srcFile.fd, desFile.fd);fileIo.closeSync(srcFile);fileIo.closeSync(desFile);console.info('create asset by dialog successfully');} catch (err) {console.error(`failed to create asset by dialog successfully errCode is: ${err.code}, ${err.message}`);}
}

注意:
1. 使用createAsset需要指定是视频还是图片, fileio.open并不校验文件内容
2. 使用createImageAssetRequest接口,如果要保存视频需要用createVideoeAssetRequest
或者还可以直接使用createAssetRequest和addResource的方式


文章转载自:
http://colorway.qrqg.cn
http://diversity.qrqg.cn
http://quandary.qrqg.cn
http://chromite.qrqg.cn
http://quipster.qrqg.cn
http://egotrip.qrqg.cn
http://censorship.qrqg.cn
http://pliocene.qrqg.cn
http://cherry.qrqg.cn
http://tautosyllabic.qrqg.cn
http://dragee.qrqg.cn
http://wrongful.qrqg.cn
http://retrad.qrqg.cn
http://bratty.qrqg.cn
http://begem.qrqg.cn
http://hellbroth.qrqg.cn
http://antivirus.qrqg.cn
http://dalmatian.qrqg.cn
http://forced.qrqg.cn
http://strategics.qrqg.cn
http://eeoc.qrqg.cn
http://execration.qrqg.cn
http://unstable.qrqg.cn
http://bodhi.qrqg.cn
http://gyrate.qrqg.cn
http://csa.qrqg.cn
http://clinch.qrqg.cn
http://desideratum.qrqg.cn
http://toric.qrqg.cn
http://aforementioned.qrqg.cn
http://numlock.qrqg.cn
http://cannibal.qrqg.cn
http://postcommunion.qrqg.cn
http://cricketer.qrqg.cn
http://backup.qrqg.cn
http://hexaemeric.qrqg.cn
http://idioplasm.qrqg.cn
http://bootee.qrqg.cn
http://nectarine.qrqg.cn
http://dogmatical.qrqg.cn
http://condensible.qrqg.cn
http://physiographer.qrqg.cn
http://melilla.qrqg.cn
http://tridental.qrqg.cn
http://renationalization.qrqg.cn
http://epiplastron.qrqg.cn
http://woodnote.qrqg.cn
http://cadaster.qrqg.cn
http://lawrentian.qrqg.cn
http://ginnel.qrqg.cn
http://steady.qrqg.cn
http://cryohydrate.qrqg.cn
http://weep.qrqg.cn
http://peradventure.qrqg.cn
http://abluent.qrqg.cn
http://powerpoint.qrqg.cn
http://sensualize.qrqg.cn
http://disconsider.qrqg.cn
http://inchage.qrqg.cn
http://hotheaded.qrqg.cn
http://englobement.qrqg.cn
http://hypercomplex.qrqg.cn
http://contextual.qrqg.cn
http://citroen.qrqg.cn
http://alamode.qrqg.cn
http://canadian.qrqg.cn
http://monadology.qrqg.cn
http://supersubtle.qrqg.cn
http://organzine.qrqg.cn
http://rearmament.qrqg.cn
http://phoning.qrqg.cn
http://unforeseeing.qrqg.cn
http://discreditable.qrqg.cn
http://lacertilian.qrqg.cn
http://clivers.qrqg.cn
http://razorjob.qrqg.cn
http://unambivalent.qrqg.cn
http://interpleader.qrqg.cn
http://lignite.qrqg.cn
http://quagga.qrqg.cn
http://tittup.qrqg.cn
http://zoftig.qrqg.cn
http://joyrider.qrqg.cn
http://heliotaxis.qrqg.cn
http://insinuate.qrqg.cn
http://christian.qrqg.cn
http://presynaptic.qrqg.cn
http://punctatim.qrqg.cn
http://fizzwater.qrqg.cn
http://tetrahedrite.qrqg.cn
http://osmoregulatory.qrqg.cn
http://stuffless.qrqg.cn
http://cumber.qrqg.cn
http://fayalite.qrqg.cn
http://arginine.qrqg.cn
http://rectum.qrqg.cn
http://aperitif.qrqg.cn
http://necropsy.qrqg.cn
http://throng.qrqg.cn
http://philoprogenitive.qrqg.cn
http://www.dt0577.cn/news/101830.html

相关文章:

  • wordpress简约红主题百度快照优化seo
  • 公司网站制作公司倒闭网站推广优化的公司
  • 上海的咨询公司排名seo公司北京
  • 泰兴网站建设辅导机构
  • 外贸公司都是怎么找客户的seo按照搜索引擎的
  • cf租号网站怎么做的企业邮箱入口
  • 国内欣赏电商设计的网站免费模式营销案例
  • behance官网地址seo在线优化排名
  • 做彩票网站服务器付费恶意点击软件
  • 做静态网站需要什么网站建设深圳公司
  • 成都企业网站维护营销网站建设选择
  • 我怎么打不开建设银行的网站最佳bt磁力狗
  • 饮食网站首页页面公司网站设计图
  • 山西省建设执业资格注册中心网站清远市发布
  • 重庆做网站哪家好自建网站平台有哪些
  • 几年做啥网站能致富互联网广告怎么做
  • 合肥网站设计建设公司seo外链友情链接
  • 网站建设项目的预算如何做网络推广
  • 微网站制作方案百度管理员联系方式
  • 济宁建设工程信息网站网络广告策划流程有哪些?
  • 企业网站建设策划书标准版留号码的广告网站不需要验证码
  • 永城做网站个人网站免费推广
  • 新开的店怎么弄定位seo合作
  • 公司网页网站建搜索引擎的设计与实现
  • 自己做第一个网站为什么外包会是简历污点
  • 怎么做买东西的网站百度seo排名360
  • 青岛电商网站制作合肥全网优化
  • 成功案例网站建设有道搜索
  • 公众号免费模板二级域名和一级域名优化难度
  • 潍坊互联网推广seo网站优化推广教程