@react-native-ohos/react-native-image-crop-picker 0.50.2 → 0.50.3-1
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/harmony/image_crop_picker/oh-package.json5 +1 -1
- package/harmony/image_crop_picker/src/main/ets/ImageCropPickerTurboModule.ts +51 -26
- package/harmony/image_crop_picker/src/main/ets/pages/CircleImageInfo.ets +1 -1
- package/harmony/image_crop_picker/src/main/ets/pages/ImageEditInfo.ets +1066 -169
- package/harmony/image_crop_picker/src/main/ets/utils/EncodeUtil.ets +38 -14
- package/harmony/image_crop_picker.har +0 -0
- package/package.json +1 -1
- package/react-native-ohos-react-native-image-crop-picker-0.50.3.tgz +0 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Please describe the basic information.",
|
|
4
4
|
"main": "index.ets",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"version": "0.50.
|
|
6
|
+
"version": "0.50.3-1",
|
|
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
|
},
|
|
@@ -295,7 +295,7 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
|
|
|
295
295
|
}
|
|
296
296
|
let tempFilePaths = null;
|
|
297
297
|
Logger.info(`${TAG} into openPicker tempFilePaths ${JSON.stringify(sourceFilePaths)}`);
|
|
298
|
-
if (
|
|
298
|
+
if (!this.isNullOrUndefined(options.compressImageQuality) || forceJpg) {
|
|
299
299
|
Logger.info(`${TAG} qualityNumber = ${qualityNumber} forceJpg = ${forceJpg}`);
|
|
300
300
|
tempFilePaths = await this.compressPictures(qualityNumber * 100, forceJpg, sourceFilePaths);
|
|
301
301
|
} else {
|
|
@@ -387,7 +387,6 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
|
|
|
387
387
|
}
|
|
388
388
|
|
|
389
389
|
async getPickerResult(options: Options, sourceFilePaths: Array<string>, tempFilePaths: Array<string>): Promise<ImageOrVideo[] | ImageOrVideo> {
|
|
390
|
-
Logger.info(`${TAG}, into openPickerResult :`);
|
|
391
390
|
let resultsList: ImageOrVideo[] = [];
|
|
392
391
|
let includeExif = this.isNullOrUndefined(options?.includeExif) ? false : options?.includeExif;
|
|
393
392
|
let images = this.isNullOrUndefined(tempFilePaths) ? sourceFilePaths : tempFilePaths;
|
|
@@ -443,8 +442,8 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
|
|
|
443
442
|
results.size = length;
|
|
444
443
|
results.creationDate = stat.ctime + '';
|
|
445
444
|
results.modificationDate = stat.mtime + '';
|
|
445
|
+
results.path = this.isNullOrUndefined(tempFilePaths) ? null : filePrefix + value;
|
|
446
446
|
if (this.isImage(value)) {
|
|
447
|
-
results.path = this.isNullOrUndefined(tempFilePaths) ? null : filePrefix + value;
|
|
448
447
|
results.data = includeBase64 ? this.imageToBase64(value) : null;
|
|
449
448
|
results.mime = 'image/' + imageType;
|
|
450
449
|
Logger.info(`${TAG} into openPickerResult value : ${value}`);
|
|
@@ -463,8 +462,9 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
|
|
|
463
462
|
results.duration = null;
|
|
464
463
|
} else {
|
|
465
464
|
Logger.info(`${TAG} into getPickerResult video start`);
|
|
466
|
-
let qualityNumber =
|
|
467
|
-
|
|
465
|
+
let qualityNumber =
|
|
466
|
+
this.isNullOrUndefined(options.compressImageQuality) ? ImageQuality : options.compressImageQuality;
|
|
467
|
+
if (!this.isNullOrUndefined(options.compressImageQuality)) {
|
|
468
468
|
results.path = this.isNullOrUndefined(tempFilePaths) ? null : value;
|
|
469
469
|
} else {
|
|
470
470
|
results.path = this.isNullOrUndefined(tempFilePaths) ? null : filePrefix + value;
|
|
@@ -549,7 +549,13 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
|
|
|
549
549
|
if (isImg) {
|
|
550
550
|
let file = fs.openSync(imgOrVideoPath, fs.OpenMode.READ_ONLY);
|
|
551
551
|
try {
|
|
552
|
-
let
|
|
552
|
+
let i = imgOrVideoPath.lastIndexOf('.');
|
|
553
|
+
let imageType = '';
|
|
554
|
+
if (i != -1) {
|
|
555
|
+
imageType = imgOrVideoPath.substring(i + 1);
|
|
556
|
+
Logger.info(`${TAG} getTempFilePaths img imageType = ${imageType}`);
|
|
557
|
+
}
|
|
558
|
+
let dstPath = this.ctx.uiAbilityContext.tempDir + '/rn_image_crop_picker_lib_temp_' + util.generateRandomUUID(true) + '.' + imageType;
|
|
553
559
|
fs.copyFileSync(file.fd, dstPath, 0);
|
|
554
560
|
imgOrVideoPath = dstPath;
|
|
555
561
|
Logger.info(`${TAG} into openCamera suc dstPath = ${dstPath}`);
|
|
@@ -560,7 +566,7 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
|
|
|
560
566
|
}
|
|
561
567
|
let tempFilePaths = null;
|
|
562
568
|
let sourceFilePaths: Array<string> = [imgOrVideoPath];
|
|
563
|
-
if (
|
|
569
|
+
if (!this.isNullOrUndefined(options.compressImageQuality) || forceJpg) {
|
|
564
570
|
Logger.info(`${TAG} into openCamera qualityNumber = ${qualityNumber} forceJpg = ${forceJpg}`);
|
|
565
571
|
tempFilePaths = await this.compressPictures(qualityNumber * 100, forceJpg, sourceFilePaths);
|
|
566
572
|
} else {
|
|
@@ -665,7 +671,8 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
|
|
|
665
671
|
|
|
666
672
|
isImage(filePath: string): boolean {
|
|
667
673
|
Logger.info(`${TAG} into isImage fileName = ${filePath}`);
|
|
668
|
-
const imageExtensionsRegex =
|
|
674
|
+
const imageExtensionsRegex =
|
|
675
|
+
/\.(jpg|jpeg|png|gif|bmp|webp|heic|heif|sdr_astc_4x4|sdr_sut_superfast_4x4|hdr_astc_4x4)$/i;
|
|
669
676
|
return imageExtensionsRegex.test(filePath);
|
|
670
677
|
}
|
|
671
678
|
|
|
@@ -690,23 +697,42 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
|
|
|
690
697
|
let imageISs = image.createImageSource(files.fd);
|
|
691
698
|
let imagePMs = await imageISs.createPixelMap();
|
|
692
699
|
let imagePackerApi = await image.createImagePacker();
|
|
693
|
-
let
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
700
|
+
let jpgToJpeg = (imageType == 'jpg' ? 'jpeg' : imageType);
|
|
701
|
+
if (imageType == 'bmp') {
|
|
702
|
+
jpgToJpeg = 'jpeg';
|
|
703
|
+
}
|
|
704
|
+
let dstPath =
|
|
705
|
+
this.ctx.uiAbilityContext.tempDir + '/rn_image_crop_picker_lib_temp_' + util.generateRandomUUID(true) +
|
|
706
|
+
'.' + imageType;
|
|
707
|
+
if (imageType == 'gif') {
|
|
708
|
+
let pixelMapList = await imageISs.createPixelMapList();
|
|
709
|
+
let options: image.PackingOption = {
|
|
710
|
+
format: `image/jpeg`,
|
|
711
|
+
quality: quality,
|
|
712
|
+
};
|
|
713
|
+
let packer = image.createImagePacker();
|
|
701
714
|
let newFile = fs.openSync(dstPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
|
|
702
|
-
|
|
715
|
+
// 只取第一帧压缩 同时将图片转为jpeg来处理压缩
|
|
716
|
+
let packerData = await packer.packToData(pixelMapList[0], options);
|
|
703
717
|
const number = fs.writeSync(newFile.fd, packerData);
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
718
|
+
fs.closeSync(newFile);
|
|
719
|
+
} else {
|
|
720
|
+
if(imageType == 'sdr_astc_4x4' || imageType == 'sdr_sut_superfast_4x4'){
|
|
721
|
+
quality = 92;
|
|
722
|
+
} else if(imageType == 'hdr_astc_4x4'){
|
|
723
|
+
quality = 85;
|
|
724
|
+
}
|
|
725
|
+
let options: image.PackingOption = {
|
|
726
|
+
format: `image/${jpgToJpeg}`,
|
|
727
|
+
quality: quality,
|
|
728
|
+
};
|
|
729
|
+
let newFile = fs.openSync(dstPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
|
|
730
|
+
let packerData = await imagePackerApi.packToData(imagePMs, options);
|
|
731
|
+
const number = fs.writeSync(newFile.fd, packerData);
|
|
732
|
+
fs.closeSync(newFile);
|
|
709
733
|
}
|
|
734
|
+
resultImages.push(dstPath);
|
|
735
|
+
fs.closeSync(files);
|
|
710
736
|
} else {
|
|
711
737
|
Logger.info(`${TAG} into compressPictures video srcPath = ${srcPath}`);
|
|
712
738
|
resultImages.push(srcPath);
|
|
@@ -851,7 +877,6 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
|
|
|
851
877
|
let imageType;
|
|
852
878
|
|
|
853
879
|
const targetFilePath = !this.isNullOrUndefined(compressOrTempFilePath) ? compressOrTempFilePath : filePath;
|
|
854
|
-
const isUsingCompressedFile = !this.isNullOrUndefined(compressOrTempFilePath);
|
|
855
880
|
|
|
856
881
|
let i = targetFilePath.lastIndexOf('/');
|
|
857
882
|
let fileName = targetFilePath.substring(i + 1);
|
|
@@ -875,12 +900,12 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
|
|
|
875
900
|
let imageIS = image.createImageSource(file.fd)
|
|
876
901
|
let imagePM = await imageIS.createPixelMap()
|
|
877
902
|
let imgInfo = await imagePM.getImageInfo();
|
|
878
|
-
|
|
903
|
+
|
|
879
904
|
videoImageInfo.data = includeBase64 ? this.imageToBase64(targetFilePath) : null;
|
|
880
905
|
videoImageInfo.height = imgInfo.size.height;
|
|
881
906
|
videoImageInfo.width = imgInfo.size.width;
|
|
882
|
-
|
|
883
907
|
videoImageInfo.exif = exifInfo;
|
|
908
|
+
|
|
884
909
|
imagePM.release().then(() => {
|
|
885
910
|
imagePM = undefined;
|
|
886
911
|
})
|
|
@@ -890,6 +915,7 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
|
|
|
890
915
|
} else {
|
|
891
916
|
videoImageInfo.mime = 'video/' + imageType;
|
|
892
917
|
let url = 'fd://' + file.fd;
|
|
918
|
+
Logger.info(`${TAG} start avPlayer url = ${url}`);
|
|
893
919
|
avMetadataExtractor = await media.createAVMetadataExtractor();
|
|
894
920
|
avMetadataExtractor.fdSrc = { fd: file.fd, offset: 0, length: length };
|
|
895
921
|
try {
|
|
@@ -940,7 +966,6 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
|
|
|
940
966
|
AppStorage.setOrCreate('showCropFrame', showCropFrame);
|
|
941
967
|
AppStorage.setOrCreate('freeStyleCropEnabled', freeStyleCropEnabled);
|
|
942
968
|
AppStorage.setOrCreate('cropperCircleOverlay', cropperCircleOverlay);
|
|
943
|
-
|
|
944
969
|
try {
|
|
945
970
|
let want: Want = {
|
|
946
971
|
"bundleName": bundleName,
|