@react-native-ohos/react-native-image-crop-picker 0.51.2-rc.2 → 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,18 @@
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
+
12
+ ### v0.51.2-rc.3
13
+
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.
15
+ - pre-release: @react-native-ohos/react-native-image-crop-picker@0.51.2-rc.3
16
+
5
17
  ### v0.51.2-rc.2
6
18
 
7
19
  - fix: When canceling the photo selection, do not display an error prompt on the interface.
@@ -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.2",
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
  },
@@ -292,12 +292,12 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
292
292
  let sourceFilePaths: Array<string> = result.photoUris as Array<string>;
293
293
  if (sourceFilePaths.length < MINIMUM_VALUE) {
294
294
  return new Promise(async (res, rej) => {
295
- rej('sourceFilePaths is empty')
295
+ Logger.info(`${TAG} sourceFilePaths is empty`);
296
296
  })
297
297
  }
298
298
  let tempFilePaths = null;
299
299
  Logger.info(`${TAG} into openPicker tempFilePaths ${JSON.stringify(sourceFilePaths)}`);
300
- if (qualityNumber !== 1 || forceJpg) {
300
+ if (!this.isNullOrUndefined(options.compressImageQuality) || forceJpg) {
301
301
  Logger.info(`${TAG} qualityNumber = ${qualityNumber} forceJpg = ${forceJpg}`);
302
302
  tempFilePaths = await this.compressPictures(qualityNumber * 100, forceJpg, sourceFilePaths);
303
303
  } else {
@@ -465,7 +465,7 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
465
465
  } else {
466
466
  Logger.info(`${TAG} into getPickerResult video start`);
467
467
  let qualityNumber = this.isNullOrUndefined(options.compressImageQuality) ? ImageQuality : options.compressImageQuality;
468
- if(qualityNumber !== 1){
468
+ if(!this.isNullOrUndefined(options.compressImageQuality)){
469
469
  results.path = this.isNullOrUndefined(tempFilePaths) ? null : value;
470
470
  } else {
471
471
  results.path = this.isNullOrUndefined(tempFilePaths) ? null : filePrefix + value;
@@ -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}`);
@@ -561,7 +567,7 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
561
567
  }
562
568
  let tempFilePaths = null;
563
569
  let sourceFilePaths: Array<string> = [imgOrVideoPath];
564
- if (qualityNumber !== 1 || forceJpg) {
570
+ if (!this.isNullOrUndefined(options.compressImageQuality) || forceJpg) {
565
571
  Logger.info(`${TAG} into openCamera qualityNumber = ${qualityNumber} forceJpg = ${forceJpg}`);
566
572
  tempFilePaths = await this.compressPictures(qualityNumber * 100, forceJpg, sourceFilePaths);
567
573
  } else {
@@ -621,7 +627,7 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
621
627
  }
622
628
  } catch (error) {
623
629
  let err = error as BusinessError;
624
- rej(JSON.stringify(err));
630
+ Logger.error(JSON.stringify(err));
625
631
  }
626
632
  })
627
633
  };
@@ -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,23 +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 options: image.PackingOption = {
695
- format: 'image/jpeg',
696
- quality: quality,
697
- };
698
- try {
699
- let packerData = await imagePackerApi.packing(imagePMs, options);
700
- Logger.info(`${TAG} into compressPictures data = ${JSON.stringify(packerData)}`);
701
- 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();
702
715
  let newFile = fs.openSync(dstPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
703
- Logger.info(`${TAG} into compressPictures newFile id = ${newFile.fd}`);
716
+ // 只取第一帧压缩 同时将图片转为jpeg来处理压缩
717
+ let packerData = await packer.packToData(pixelMapList[0], options);
704
718
  const number = fs.writeSync(newFile.fd, packerData);
705
- Logger.info(`${TAG} into compressPictures write data to file succeed size = ${number}`);
706
- resultImages.push(dstPath);
707
- fs.closeSync(files);
708
- } catch (err) {
709
- 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);
710
734
  }
735
+ resultImages.push(dstPath);
736
+ fs.closeSync(files);
711
737
  } else {
712
738
  Logger.info(`${TAG} into compressPictures video srcPath = ${srcPath}`);
713
739
  resultImages.push(srcPath);
@@ -804,7 +830,7 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
804
830
  Logger.info(`${TAG} into openCropper imgPath = ${imgPath}`);
805
831
  if (this.isNullOrUndefined(imgPath)) {
806
832
  return new Promise(async (res, rej) => {
807
- rej('imgPath is null')
833
+ Logger.info(`${TAG} imgPath is null`);
808
834
  })
809
835
  }
810
836
  let tempFilePaths = null;
@@ -941,6 +967,7 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
941
967
  AppStorage.setOrCreate('showCropFrame', showCropFrame);
942
968
  AppStorage.setOrCreate('freeStyleCropEnabled', freeStyleCropEnabled);
943
969
  AppStorage.setOrCreate('cropperCircleOverlay', cropperCircleOverlay);
970
+
944
971
  try {
945
972
  let want: Want = {
946
973
  "bundleName": bundleName,
@@ -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)