Load and resize assets on iOS with proper orientation
This commit is contained in:
parent
e9b1dec7b0
commit
7d19fab226
|
@ -45,9 +45,18 @@ RCT_EXPORT_METHOD(createResizedImage:(NSString *)path width:(float)width height:
|
||||||
|
|
||||||
// Ask for the "Asset" for the URL. An asset is a representation of an image in the Photo application.
|
// Ask for the "Asset" for the URL. An asset is a representation of an image in the Photo application.
|
||||||
[library assetForURL:url resultBlock:^(ALAsset *asset) {
|
[library assetForURL:url resultBlock:^(ALAsset *asset) {
|
||||||
// Here, we have the asset, let's retrieve the image from it
|
ALAssetRepresentation* representation = [asset defaultRepresentation];
|
||||||
CGImageRef imgRef = [[asset defaultRepresentation] fullResolutionImage];
|
|
||||||
UIImage * image = [UIImage imageWithCGImage:imgRef];
|
// Retrieve the image orientation from the ALAsset
|
||||||
|
UIImageOrientation orientation = UIImageOrientationUp;
|
||||||
|
NSNumber* orientationValue = [asset valueForProperty:@"ALAssetPropertyOrientation"];
|
||||||
|
if (orientationValue != nil) {
|
||||||
|
orientation = [orientationValue intValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
CGFloat scale = 1;
|
||||||
|
UIImage* image = [UIImage imageWithCGImage:[representation fullResolutionImage]
|
||||||
|
scale:scale orientation:orientation];
|
||||||
|
|
||||||
//Do the resizing
|
//Do the resizing
|
||||||
UIImage * scaledImage = [image scaleToSize:newSize];
|
UIImage * scaledImage = [image scaleToSize:newSize];
|
||||||
|
|
Loading…
Reference in New Issue