mirror of
https://github.com/DmcSDK/cordova-plugin-mediaPicker
synced 2024-10-06 00:22:11 +08:00
Convert HEIC Images to JPG
When using/expecting .JPG images from this plugin you will often receive no image returned as Photo captured outside of your app may be stored in HEIC format. This update converts any images being selected from the Gallery to go from HEIC to JPG.
This commit is contained in:
parent
9c15c4964c
commit
23e89aae69
@ -77,8 +77,10 @@
|
||||
|
||||
-(void)imageToSandbox:(PHAsset *)asset dmcPickerPath:(NSString*)dmcPickerPath aListArray:(NSMutableArray*)aListArray selectArray:(NSMutableArray*)selectArray index:(int)index{
|
||||
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
|
||||
options.synchronous = NO;
|
||||
options.networkAccessAllowed = YES;
|
||||
options.resizeMode = PHImageRequestOptionsResizeModeFast;
|
||||
options.version = PHImageRequestOptionsVersionCurrent;
|
||||
options.progressHandler = ^(double progress, NSError *error, BOOL *stop, NSDictionary *info) {
|
||||
NSString *compressCompletedjs = [NSString stringWithFormat:@"MediaPicker.icloudDownloadEvent(%f,%i)", progress,index];
|
||||
[self.commandDelegate evalJs:compressCompletedjs];
|
||||
@ -86,6 +88,10 @@
|
||||
[[PHImageManager defaultManager] requestImageDataForAsset:asset options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
|
||||
if(imageData != nil) {
|
||||
NSString *filename=[asset valueForKey:@"filename"];
|
||||
if ([filename hasSuffix:@".HEIC"]) {
|
||||
imageData = UIImageJPEGRepresentation([UIImage imageWithData:imageData], 1);
|
||||
filename = [filename stringByReplacingOccurrencesOfString:@".HEIC" withString:@".JPG"];
|
||||
}
|
||||
NSString *fullpath=[NSString stringWithFormat:@"%@/%@%@", dmcPickerPath,[[NSProcessInfo processInfo] globallyUniqueString], filename];
|
||||
NSNumber *size=[NSNumber numberWithLong:imageData.length];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user