@react-native-ohos/react-native-image-crop-picker 0.51.2-rc.3 → 0.51.2-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## 鸿蒙化Log
4
4
 
5
+ ### v0.51.2-rc.4
6
+
7
+ - Fix: Support for multiple image formats in image compression. Fixed issues with openPicker and openCamera where circular cropping of images did not display properly.
8
+ - Fix: Adjust to retain the original format of the image after cropping it.
9
+ - Fix: Address the issue where the image cropping frame cannot be dragged. Optimize the position dragging of the cropping frame to ensure it remains centered and maintains consistent iOS effect.
10
+ - pre-release: @react-native-ohos/react-native-image-crop-picker@0.51.2-rc.4
11
+
5
12
  ### v0.51.2-rc.3
6
13
 
7
14
  - fix: The issue of the PNG image being larger in memory than the one generated with a compression ratio of 0.8 to 1 has been resolved.
@@ -3,7 +3,7 @@
3
3
  "description": "Please describe the basic information.",
4
4
  "main": "index.ets",
5
5
  "type": "module",
6
- "version": "0.51.2-rc.3",
6
+ "version": "0.51.2-rc.4",
7
7
  "dependencies": {
8
8
  "@rnoh/react-native-openharmony": "file:../../node_modules/@react-native-oh/react-native-harmony/harmony/react_native_openharmony.har"
9
9
  },
@@ -550,7 +550,13 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
550
550
  if (isImg) {
551
551
  let file = fs.openSync(imgOrVideoPath, fs.OpenMode.READ_ONLY);
552
552
  try {
553
- let dstPath = this.ctx.uiAbilityContext.tempDir + '/rn_image_crop_picker_lib_temp_' + util.generateRandomUUID(true) + '.jpeg';
553
+ let i = imgOrVideoPath.lastIndexOf('.');
554
+ let imageType = '';
555
+ if (i != -1) {
556
+ imageType = imgOrVideoPath.substring(i + 1);
557
+ Logger.info(`${TAG} getTempFilePaths img imageType = ${imageType}`);
558
+ }
559
+ let dstPath = this.ctx.uiAbilityContext.tempDir + '/rn_image_crop_picker_lib_temp_' + util.generateRandomUUID(true) + '.' + imageType;
554
560
  fs.copyFileSync(file.fd, dstPath, 0);
555
561
  imgOrVideoPath = dstPath;
556
562
  Logger.info(`${TAG} into openCamera suc dstPath = ${dstPath}`);
@@ -666,7 +672,8 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
666
672
 
667
673
  isImage(filePath: string): boolean {
668
674
  Logger.info(`${TAG} into isImage fileName = ${filePath}`);
669
- const imageExtensionsRegex = /\.(jpg|jpeg|png|gif|bmp|webp|heic)$/i;
675
+ const imageExtensionsRegex =
676
+ /\.(jpg|jpeg|png|gif|bmp|webp|heic|heif|sdr_astc_4x4|sdr_sut_superfast_4x4|hdr_astc_4x4)$/i;
670
677
  return imageExtensionsRegex.test(filePath);
671
678
  }
672
679
 
@@ -691,24 +698,42 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
691
698
  let imageISs = image.createImageSource(files.fd);
692
699
  let imagePMs = await imageISs.createPixelMap();
693
700
  let imagePackerApi = await image.createImagePacker();
694
- let jpgToJpeg = (imageType == 'jpg' ? 'jpeg':imageType);
695
- let options: image.PackingOption = {
696
- format: `image/${jpgToJpeg}`,
697
- quality: quality,
698
- };
699
- try {
700
- let packerData = await imagePackerApi.packing(imagePMs, options);
701
- Logger.info(`${TAG} into compressPictures data = ${JSON.stringify(packerData)}`);
702
- let dstPath = this.ctx.uiAbilityContext.tempDir + '/rn_image_crop_picker_lib_temp_' + util.generateRandomUUID(true) + '.' + imageType;
701
+ let jpgToJpeg = (imageType == 'jpg' ? 'jpeg' : imageType);
702
+ if (imageType == 'bmp') {
703
+ jpgToJpeg = 'jpeg';
704
+ }
705
+ let dstPath =
706
+ this.ctx.uiAbilityContext.tempDir + '/rn_image_crop_picker_lib_temp_' + util.generateRandomUUID(true) +
707
+ '.' + imageType;
708
+ if (imageType == 'gif') {
709
+ let pixelMapList = await imageISs.createPixelMapList();
710
+ let options: image.PackingOption = {
711
+ format: `image/jpeg`,
712
+ quality: quality,
713
+ };
714
+ let packer = image.createImagePacker();
703
715
  let newFile = fs.openSync(dstPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
704
- Logger.info(`${TAG} into compressPictures newFile id = ${newFile.fd}`);
716
+ // 只取第一帧压缩 同时将图片转为jpeg来处理压缩
717
+ let packerData = await packer.packToData(pixelMapList[0], options);
705
718
  const number = fs.writeSync(newFile.fd, packerData);
706
- Logger.info(`${TAG} into compressPictures write data to file succeed size = ${number}`);
707
- resultImages.push(dstPath);
708
- fs.closeSync(files);
709
- } catch (err) {
710
- Logger.error(`${TAG} into compressPictures write data to file failed err = ${JSON.stringify(err)}`);
719
+ fs.closeSync(newFile);
720
+ } else {
721
+ if(imageType == 'sdr_astc_4x4' || imageType == 'sdr_sut_superfast_4x4'){
722
+ quality = 92;
723
+ } else if(imageType == 'hdr_astc_4x4'){
724
+ quality = 85;
725
+ }
726
+ let options: image.PackingOption = {
727
+ format: `image/${jpgToJpeg}`,
728
+ quality: quality,
729
+ };
730
+ let newFile = fs.openSync(dstPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
731
+ let packerData = await imagePackerApi.packToData(imagePMs, options);
732
+ const number = fs.writeSync(newFile.fd, packerData);
733
+ fs.closeSync(newFile);
711
734
  }
735
+ resultImages.push(dstPath);
736
+ fs.closeSync(files);
712
737
  } else {
713
738
  Logger.info(`${TAG} into compressPictures video srcPath = ${srcPath}`);
714
739
  resultImages.push(srcPath);
@@ -1070,9 +1095,9 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
1070
1095
  .then((data: PermissionRequestResult) => {
1071
1096
  res(data?.authResults[0] === 0)
1072
1097
  }).catch((err) => {
1073
- res(false)
1074
- Logger.info(`${TAG} grantPermission err = ${JSON.stringify(err)}`);
1075
- })
1098
+ res(false)
1099
+ Logger.info(`${TAG} grantPermission err = ${JSON.stringify(err)}`);
1100
+ })
1076
1101
  });
1077
1102
  }
1078
1103
  }
@@ -5,7 +5,7 @@
5
5
  export namespace ImageCropPicker {
6
6
  export const NAME = 'ImageCropPicker' as const
7
7
 
8
- export type CropperOptions = {multiple?: boolean, minFiles?: number, maxFiles?: number, waitAnimationEnd?: boolean, smartAlbums?: unknown[], useFrontCamera?: boolean, loadingLabelText?: string, showsSelectedCount?: boolean, sortOrder?: string, hideBottomControls?: boolean, writeTempFile?: boolean, mediaType: string, width?: number, height?: number, includeBase64?: boolean, includeExif?: boolean, forceJpg?: boolean, cropping?: boolean, avoidEmptySpaceAroundImage?: boolean, cropperActiveWidgetColor?: string, cropperStatusBarColor?: string, cropperToolbarColor?: string, cropperToolbarWidgetColor?: string, cropperToolbarTitle?: string, freeStyleCropEnabled?: boolean, cropperTintColor?: string, cropperCircleOverlay?: boolean, cropperCancelText?: string, cropperCancelColor?: string, cropperChooseText?: string, cropperChooseColor?: string, cropperRotateButtonHidden?: boolean, showCropGuidelines?: boolean, showCropFrame?: boolean, enableRotationGesture?: boolean, disableCropperColorSetters?: boolean, compressImageMaxWidth?: number, compressImageMaxHeight?: number, compressImageQuality?: number, path: string}
8
+ export type CropperOptions = {multiple?: boolean, minFiles?: number, maxFiles?: number, waitAnimationEnd?: boolean, smartAlbums?: unknown[], useFrontCamera?: boolean, loadingLabelText?: string, showsSelectedCount?: boolean, sortOrder?: string, hideBottomControls?: boolean, writeTempFile?: boolean, mediaType: string, width?: number, height?: number, includeBase64?: boolean, includeExif?: boolean, forceJpg?: boolean, cropping?: boolean, avoidEmptySpaceAroundImage?: boolean, cropperActiveWidgetColor?: string, cropperStatusBarLight?: boolean, cropperNavigationBarLight?: boolean, cropperToolbarColor?: string, cropperToolbarWidgetColor?: string, cropperToolbarTitle?: string, freeStyleCropEnabled?: boolean, cropperTintColor?: string, cropperCircleOverlay?: boolean, cropperCancelText?: string, cropperCancelColor?: string, cropperChooseText?: string, cropperChooseColor?: string, cropperRotateButtonHidden?: boolean, showCropGuidelines?: boolean, showCropFrame?: boolean, enableRotationGesture?: boolean, disableCropperColorSetters?: boolean, compressImageMaxWidth?: number, compressImageMaxHeight?: number, compressImageQuality?: number, path: string}
9
9
 
10
10
  export type Exif = {}
11
11
 
@@ -192,7 +192,7 @@ export struct CropView {
192
192
  build() {
193
193
  Stack() {
194
194
  Stack() {
195
- Image(this.model.path)
195
+ Image(this.model.src)
196
196
  .width('100%')
197
197
  .height('100%')
198
198
  .alt(this.model.previewSource)