HarmonyOS 横向拍照的身份证图片,如何旋转-90度显示到Image组件上?现在显示是竖的,变形了

HarmonyOS
2024-12-23 16:23:59
1135浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Excelsior_abit

可参考以下demo,参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-transformation-V5#rotate

import { BusinessError, request } from '@kit.BasicServicesKit';
import fs from '@ohos.file.fs';
import { photoAccessHelper } from '@kit.MediaLibraryKit';
import { image } from '@kit.ImageKit';

@Entry
@Component
struct Index {
  @State imgUrl: PixelMap | undefined = undefined;
  build() {

    Column() {
      Button('选择图片旋转').onClick(() => {
        const photoSelectOptions = new photoAccessHelper.PhotoSelectOptions();
        photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; // 过滤选择媒体文件类型为IMAGE
        photoSelectOptions.maxSelectNumber = 1;

        const photoViewPicker = new photoAccessHelper.PhotoViewPicker();
        //拍照或选择图片
        photoViewPicker.select(photoSelectOptions).then((photoSelectResult: photoAccessHelper.PhotoSelectResult) => {
          photoSelectResult.photoUris.forEach((uri) => {
            let file = fs.openSync(uri, fs.OpenMode.CREATE);
            image.createImageSource(file.fd).createPixelMap().then((pixelMap: PixelMap) => {
              pixelMap.rotate(90).then(()=>{
                console.log('rotate success')
                this.imgUrl = pixelMap;
              }).catch((err: BusinessError)=>{
                console.log('rotate fail with err '+JSON.stringify(err))
              });
            });
          })
        }).catch((err: BusinessError) => {
          console.error(`Invoke photoViewPicker.select failed, code is ${err.code}, message is ${err.message}`);
        })
      })
      Image(this.imgUrl).height(100).width(100)
    }
    .width('100%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
分享
微博
QQ
微信
回复
2024-12-23 19:39:17
相关问题
HarmonyOS 身份证nfc读取规范
1236浏览 • 2回复 待解决
HarmonyOS nfc识别身份证能力
1292浏览 • 2回复 待解决
HarmonyOS转屏后视频画面90显示
1185浏览 • 1回复 待解决
HarmonyOS 是否具备身份证OCR识别能力
1184浏览 • 1回复 待解决
HarmonyOS 身份证ocr技术对接接口文档
863浏览 • 1回复 待解决
HarmonyOS OCR扫银行卡、身份证能力
936浏览 • 1回复 待解决
HarmonyOS OCR识别:银行卡和身份证识别
1223浏览 • 2回复 待解决
List列表组件如何改为横向显示
1626浏览 • 1回复 待解决