Add width property on iOS. Allows to specify an image width on capture

This commit is contained in:
Michaël Villeneuve 2018-02-23 16:08:45 +01:00
parent 983337d9f8
commit 27ea6b04c2
3 changed files with 39 additions and 0 deletions

View File

@ -324,6 +324,17 @@ static NSDictionary *defaultFaceDetectorOptions = nil;
if ([options[@"mirrorImage"] boolValue]) {
takenImage = [RNImageUtils mirrorImage:takenImage];
}
<<<<<<< HEAD
=======
if ([options[@"width"] integerValue]) {
takenImage = [RNImageUtils scaleImage:takenImage toWidth:[options[@"width"] integerValue]];
}
if ([options[@"forceUpOrientation"] boolValue]) {
takenImage = [RNImageUtils forceUpOrientation:takenImage];
}
>>>>>>> c03db73... Add width property on iOS. Allows to specify an image width on capture
NSMutableDictionary *response = [[NSMutableDictionary alloc] init];
float quality = [options[@"quality"] floatValue];

View File

@ -15,6 +15,7 @@
+ (UIImage *)cropImage:(UIImage *)image toRect:(CGRect)rect;
+ (UIImage *)mirrorImage:(UIImage *)image;
+ (NSString *)writeImage:(NSData *)image toPath:(NSString *)path;
+ (UIImage *) scaleImage:(UIImage*)image toWidth:(NSInteger)width;
+ (void)updatePhotoMetadata:(CMSampleBufferRef)imageSampleBuffer withAdditionalData:(NSDictionary *)additionalData inResponse:(NSMutableDictionary *)response;
@end

View File

@ -68,6 +68,33 @@
return [fileURL absoluteString];
}
<<<<<<< HEAD
=======
+ (UIImage *) scaleImage:(UIImage*)image toWidth:(NSInteger)width
{
width /= [UIScreen mainScreen].scale; // prevents image from being incorrectly resized on retina displays
float scaleRatio = (float) width / (float) image.size.width;
CGSize size = CGSizeMake(width, (int) (image.size.height * scaleRatio));
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return [UIImage imageWithCGImage:[newImage CGImage] scale:1.0 orientation:(newImage.imageOrientation)];
}
+ (UIImage *)forceUpOrientation:(UIImage *)image
{
if (image.imageOrientation != UIImageOrientationUp) {
UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);
[image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
return image;
}
>>>>>>> c03db73... Add width property on iOS. Allows to specify an image width on capture
+ (void)updatePhotoMetadata:(CMSampleBufferRef)imageSampleBuffer withAdditionalData:(NSDictionary *)additionalData inResponse:(NSMutableDictionary *)response
{
CFDictionaryRef exifAttachments = CMGetAttachment(imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);