相册选择一张图片后,如何进入系统自带的图片编辑页

let PhotoSelectOptions = new photoAccessHelper.PhotoSelectOptions(); 
PhotoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; 
PhotoSelectOptions.maxSelectNumber = 1; 
PhotoSelectOptions.isEditSupported=true; 
 
let photoPicker = new photoAccessHelper.PhotoViewPicker(); 
photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult: photoAccessHelper.PhotoSelectResult) => { 
  console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); 
}).catch((err: BusinessError) => { 
  console.error(`PhotoViewPicker.select failed with err: ${err.code}, ${err.message}`); 
});

使用如上代码:配置了属性PhotoSelectOptions.isEditSupported=true;但是点击了右上角的编辑按钮,页面小时,返回了空数据。

HarmonyOS
2024-09-10 11:03:48
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
put_get

图库选择器对象,用来支撑选择图片/视频和保存图片/视频等用户场景。选择文件推荐使用PhotoAccessHelper的PhotoViewPicker。在使用前,需要先创建PhotoViewPicker实例。let photoPicker = new picker.PhotoViewPicker();

关键代码如下:

let photoPicker = new picker.PhotoViewPicker(); 
photoPicker.select({ 
  MIMEType: picker.PhotoViewMIMETypes.IMAGE_TYPE, 
  maxSelectNumber: 5, 
}, async (err, data) => { 
  if (err) { 
    console.info("photopicker:" + err.message) 
    return 
  } 
  this.imgArray = data.photoUris 
  let tempPath = await this.beginScan(data.photoUris[0]) 
  let sourceOptions: image.SourceOptions = { sourceDensity: 120 }; 
  const imagePackerApi: image.ImagePacker = image.createImagePacker(); 
  const imageSourceApi: image.ImageSource = image.createImageSource(tempPath, sourceOptions); 
 
  console.log(`${imageSourceApi}`) 
  let packOpts: image.PackingOption = { format: "image/jpeg", quality: 98 }; 
  imagePackerApi.packing(imageSourceApi, packOpts, (err: BusinessError, data: ArrayBuffer) => { 
    if (err) { 
      console.log(`${err}`) 
      console.error('packing failed.'); 
    } else { 
      console.log(`${data.byteLength}`) 
      console.info('packing succeeded.'); 
    } 
  }) 
})

可参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-file-picker-V5

分享
微博
QQ
微信
回复
2024-09-10 16:39:35
相关问题
如何保存一张PNG图片相册
1853浏览 • 1回复 待解决
如何吸取一张图片色值?
405浏览 • 1回复 待解决
进入相册或拍照选择图片做头像
13602浏览 • 2回复 已解决
如何一张图片转化为PixelMapElement
10023浏览 • 1回复 待解决
如何编辑裁剪相册图片
558浏览 • 1回复 待解决
如何相册图片进行编辑裁剪
1794浏览 • 1回复 待解决
拉起相册选择图片页面失败
1950浏览 • 1回复 待解决