@react-native-ohos/react-native-image-crop-picker 0.40.5-rc.7 → 0.40.5-rc.8

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.
@@ -3,7 +3,7 @@
3
3
  "description": "Please describe the basic information.",
4
4
  main: 'index.ets',
5
5
  type: 'module',
6
- version: '0.40.5-rc.7',
6
+ version: '0.40.5-rc.8',
7
7
  dependencies: {
8
8
  "@rnoh/react-native-openharmony": "^0.72.38"
9
9
  },
@@ -20,8 +20,6 @@ import { JSON } from '@kit.ArkTS';
20
20
  import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl';
21
21
  import { PermissionRequestResult } from '@ohos.abilityAccessCtrl';
22
22
 
23
- import { window } from '@kit.ArkUI';
24
-
25
23
 
26
24
  export type MediaType = 'photo' | 'video' | 'any';
27
25
 
@@ -275,7 +273,7 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
275
273
  }
276
274
  let tempFilePaths = null;
277
275
  Logger.info(`${TAG} into openPicker tempFilePaths ${JSON.stringify(sourceFilePaths)}`);
278
- if (qualityNumber !== 1 || forceJpg) {
276
+ if (!this.isNullOrUndefined(options.compressImageQuality) || forceJpg) {
279
277
  Logger.info(`${TAG} qualityNumber = ${qualityNumber} forceJpg = ${forceJpg}`);
280
278
  tempFilePaths = await this.compressPictures(qualityNumber * 100, forceJpg, sourceFilePaths);
281
279
  } else {
@@ -367,7 +365,6 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
367
365
  }
368
366
 
369
367
  async getPickerResult(options: Options, sourceFilePaths: Array<string>, tempFilePaths: Array<string>): Promise<ImageOrVideo[] | ImageOrVideo> {
370
- Logger.info(`${TAG}, into openPickerResult :`);
371
368
  let resultsList: ImageOrVideo[] = [];
372
369
  let includeExif = this.isNullOrUndefined(options?.includeExif) ? false : options?.includeExif;
373
370
  let images = this.isNullOrUndefined(tempFilePaths) ? sourceFilePaths : tempFilePaths;
@@ -423,8 +420,8 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
423
420
  results.size = length;
424
421
  results.creationDate = stat.ctime + '';
425
422
  results.modificationDate = stat.mtime + '';
423
+ results.path = this.isNullOrUndefined(tempFilePaths) ? null : filePrefix + value;
426
424
  if (this.isImage(value)) {
427
- results.path = this.isNullOrUndefined(tempFilePaths) ? null : filePrefix + value;
428
425
  results.data = includeBase64 ? this.imageToBase64(value) : null;
429
426
  results.mime = 'image/' + imageType;
430
427
  Logger.info(`${TAG} into openPickerResult value : ${value}`);
@@ -443,8 +440,9 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
443
440
  results.duration = null;
444
441
  } else {
445
442
  Logger.info(`${TAG} into getPickerResult video start`);
446
- let qualityNumber = this.isNullOrUndefined(options.compressImageQuality) ? ImageQuality : options.compressImageQuality;
447
- if(qualityNumber !== 1){
443
+ let qualityNumber =
444
+ this.isNullOrUndefined(options.compressImageQuality) ? ImageQuality : options.compressImageQuality;
445
+ if (!this.isNullOrUndefined(options.compressImageQuality)) {
448
446
  results.path = this.isNullOrUndefined(tempFilePaths) ? null : value;
449
447
  } else {
450
448
  results.path = this.isNullOrUndefined(tempFilePaths) ? null : filePrefix + value;
@@ -529,7 +527,13 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
529
527
  if (isImg) {
530
528
  let file = fs.openSync(imgOrVideoPath, fs.OpenMode.READ_ONLY);
531
529
  try {
532
- let dstPath = this.ctx.uiAbilityContext.tempDir + '/rn_image_crop_picker_lib_temp_' + util.generateRandomUUID(true) + '.jpeg';
530
+ let i = imgOrVideoPath.lastIndexOf('.');
531
+ let imageType = '';
532
+ if (i != -1) {
533
+ imageType = imgOrVideoPath.substring(i + 1);
534
+ Logger.info(`${TAG} getTempFilePaths img imageType = ${imageType}`);
535
+ }
536
+ let dstPath = this.ctx.uiAbilityContext.tempDir + '/rn_image_crop_picker_lib_temp_' + util.generateRandomUUID(true) + '.' + imageType;
533
537
  fs.copyFileSync(file.fd, dstPath, 0);
534
538
  imgOrVideoPath = dstPath;
535
539
  Logger.info(`${TAG} into openCamera suc dstPath = ${dstPath}`);
@@ -540,7 +544,7 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
540
544
  }
541
545
  let tempFilePaths = null;
542
546
  let sourceFilePaths: Array<string> = [imgOrVideoPath];
543
- if (qualityNumber !== 1 || forceJpg) {
547
+ if (!this.isNullOrUndefined(options.compressImageQuality) || forceJpg) {
544
548
  Logger.info(`${TAG} into openCamera qualityNumber = ${qualityNumber} forceJpg = ${forceJpg}`);
545
549
  tempFilePaths = await this.compressPictures(qualityNumber * 100, forceJpg, sourceFilePaths);
546
550
  } else {
@@ -645,7 +649,8 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
645
649
 
646
650
  isImage(filePath: string): boolean {
647
651
  Logger.info(`${TAG} into isImage fileName = ${filePath}`);
648
- const imageExtensionsRegex = /\.(jpg|jpeg|png|gif|bmp|webp|heic)$/i;
652
+ const imageExtensionsRegex =
653
+ /\.(jpg|jpeg|png|gif|bmp|webp|heic|heif|sdr_astc_4x4|sdr_sut_superfast_4x4|hdr_astc_4x4)$/i;
649
654
  return imageExtensionsRegex.test(filePath);
650
655
  }
651
656
 
@@ -670,23 +675,42 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
670
675
  let imageISs = image.createImageSource(files.fd);
671
676
  let imagePMs = await imageISs.createPixelMap();
672
677
  let imagePackerApi = await image.createImagePacker();
673
- let options: image.PackingOption = {
674
- format: 'image/jpeg',
675
- quality: quality,
676
- };
677
- try {
678
- let packerData = await imagePackerApi.packing(imagePMs, options);
679
- Logger.info(`${TAG} into compressPictures data = ${JSON.stringify(packerData)}`);
680
- let dstPath = this.ctx.uiAbilityContext.tempDir + '/rn_image_crop_picker_lib_temp_' + util.generateRandomUUID(true) + '.' + imageType;
678
+ let jpgToJpeg = (imageType == 'jpg' ? 'jpeg' : imageType);
679
+ if (imageType == 'bmp') {
680
+ jpgToJpeg = 'jpeg';
681
+ }
682
+ let dstPath =
683
+ this.ctx.uiAbilityContext.tempDir + '/rn_image_crop_picker_lib_temp_' + util.generateRandomUUID(true) +
684
+ '.' + imageType;
685
+ if (imageType == 'gif') {
686
+ let pixelMapList = await imageISs.createPixelMapList();
687
+ let options: image.PackingOption = {
688
+ format: `image/jpeg`,
689
+ quality: quality,
690
+ };
691
+ let packer = image.createImagePacker();
681
692
  let newFile = fs.openSync(dstPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
682
- Logger.info(`${TAG} into compressPictures newFile id = ${newFile.fd}`);
693
+ // 只取第一帧压缩(保持与IOS一致) 同时将图片转为jpeg来处理压缩
694
+ let packerData = await packer.packToData(pixelMapList[0], options);
683
695
  const number = fs.writeSync(newFile.fd, packerData);
684
- Logger.info(`${TAG} into compressPictures write data to file succeed size = ${number}`);
685
- resultImages.push(dstPath);
686
- fs.closeSync(files);
687
- } catch (err) {
688
- Logger.error(`${TAG} into compressPictures write data to file failed err = ${JSON.stringify(err)}`);
696
+ fs.closeSync(newFile);
697
+ } else {
698
+ if(imageType == 'sdr_astc_4x4' || imageType == 'sdr_sut_superfast_4x4'){
699
+ quality = 92;
700
+ } else if(imageType == 'hdr_astc_4x4'){
701
+ quality = 85;
702
+ }
703
+ let options: image.PackingOption = {
704
+ format: `image/${jpgToJpeg}`,
705
+ quality: quality,
706
+ };
707
+ let newFile = fs.openSync(dstPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
708
+ let packerData = await imagePackerApi.packToData(imagePMs, options);
709
+ const number = fs.writeSync(newFile.fd, packerData);
710
+ fs.closeSync(newFile);
689
711
  }
712
+ resultImages.push(dstPath);
713
+ fs.closeSync(files);
690
714
  } else {
691
715
  Logger.info(`${TAG} into compressPictures video srcPath = ${srcPath}`);
692
716
  resultImages.push(srcPath);
@@ -843,7 +867,7 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
843
867
  videoImageInfo.filename = fileName;
844
868
  videoImageInfo.mime = 'image/' + imageType;
845
869
 
846
- let file = fs.openSync(targetFilePath, fs.OpenMode.READ_ONLY)
870
+ let file = fs.openSync(targetFilePath, fs.OpenMode.READ_ONLY);
847
871
  let stat = fs.statSync(file.fd);
848
872
  let length = stat.size;
849
873
  videoImageInfo.size = length;
@@ -198,7 +198,7 @@ export struct CropView {
198
198
  build() {
199
199
  Stack() {
200
200
  Stack() {
201
- Image(this.model.path)
201
+ Image(this.model.src)
202
202
  .width('100%')
203
203
  .height('100%')
204
204
  .alt(this.model.previewSource)