HarmonyOS 鸿蒙Next支持上传相册图片吗?类似于截图的这种功能

发布于 1周前 作者 gougou168 来自 鸿蒙OS

HarmonyOS 鸿蒙Next支持上传相册图片吗?类似于截图的这种功能 鸿蒙支持上传相册图片吗?类似于截图的这种功能

3 回复

参考以下Demo

import { BusinessError } from '@ohos.base';
import picker from '@ohos.file.picker';

async function example01() {
  try {
    let uris: Record<string, Object> = {};
    let photoSelectOptions = new picker.PhotoSelectOptions();
    photoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE;
    photoSelectOptions.maxSelectNumber = 5;
    let photoPicker = new picker.PhotoViewPicker();
    photoPicker.select(photoSelectOptions).then((photoSelectResult: picker.PhotoSelectResult) => {
      uris['data'] = photoSelectResult.photoUris;
      console.info('PhotoViewPicker.select successfully, photoSelectResult uri: ' + JSON.stringify(photoSelectResult));
    }).catch((err: BusinessError) => {
      console.error('PhotoViewPicker.select failed with err: ' + JSON.stringify(err));
    });
  } catch (error) {
    let err: BusinessError = error as BusinessError;
    console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err));
  }
}

@Entry
@Component
struct Index {
  @State message: string = 'Hello World';
  @State photoUri: string = '';

  build() {
    Column() {
      Text(this.message)
        .id('HelloWorld')
        .fontSize(50)
        .fontWeight(FontWeight.Bold)
        .alignRules({
          center: { anchor: '__container__', align: VerticalAlign.Center },
          middle: { anchor: '__container__', align: HorizontalAlign.Center }
        })
        .onClick(() => {
          try {
            let photoSelectOptions = new picker.PhotoSelectOptions();
            photoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE;
            photoSelectOptions.maxSelectNumber = 5;
            let photoPicker = new picker.PhotoViewPicker();
            photoPicker.select(photoSelectOptions).then((photoSelectResult: picker.PhotoSelectResult) => {
              this.photoUri = photoSelectResult.photoUris[0];
              console.log("111")
              console.log(JSON.stringify(this.photoUri))
              console.info('PhotoViewPicker.select successfully, photoSelectResult uri: ' + JSON.stringify(photoSelectResult));
            }).catch((err: BusinessError) => {
              console.error('PhotoViewPicker.select failed with err: ' + JSON.stringify(err));
            });
          } catch (error) {
            let err: BusinessError = error as BusinessError;
            console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err));
          }
        })
      Image(`${this.photoUri}`)
        .width(100)
        .height(100)
    }
    .height('100%')
    .width('100%')
  }
}

更多关于HarmonyOS 鸿蒙Next支持上传相册图片吗?类似于截图的这种功能的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


HarmonyOS 鸿蒙Next支持上传相册图片

HarmonyOS 鸿蒙Next系统作为华为推出的新一代操作系统,在功能设计上充分考虑了用户的实际需求。关于上传相册图片的功能,HarmonyOS 鸿蒙Next是支持的。用户可以在系统内轻松访问相册,并选择想要上传的图片。这一功能与截图功能类似,都允许用户从设备存储中选择并分享图片。

在HarmonyOS 鸿蒙Next系统中,上传相册图片通常涉及以下几个步骤:首先,打开需要上传图片的应用或功能;其次,在应用内找到并选择“上传”或“分享”选项;接着,系统会引导用户访问相册,此时用户可以在相册中浏览并选择想要上传的图片;最后,确认选择并上传图片。

值得注意的是,具体的操作步骤可能会因应用的不同而有所差异。但总体来说,HarmonyOS 鸿蒙Next系统为用户提供了便捷的图片上传功能,使得分享和传输图片变得更加简单和高效。

如果在使用过程中遇到任何问题,或者对上传相册图片的功能有更多疑问,建议直接访问HarmonyOS的官方网站或相关论坛进行查询。如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html

回到顶部