diff --git a/AUTHORS b/AUTHORS index ed6942ae1a6e..395826989e1f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -43,4 +43,5 @@ Audrius Karosevicius Lukasz Piliszczuk SoundReply Solutions GmbH Rafal Wachol -Pau Picas \ No newline at end of file +Pau Picas +Cédric Wyss diff --git a/packages/image_picker/CHANGELOG.md b/packages/image_picker/CHANGELOG.md index 78d44e594eb5..342888d758c2 100644 --- a/packages/image_picker/CHANGELOG.md +++ b/packages/image_picker/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.6.1+5 + +* iOS: Fix image_picker scaling of images which were taken in portrait mode. + ## 0.6.1+4 * Android: Fix a regression where the `retrieveLostImage` does not work anymore. diff --git a/packages/image_picker/ios/Classes/FLTImagePickerImageUtil.m b/packages/image_picker/ios/Classes/FLTImagePickerImageUtil.m index 000bd4bf9c66..3b55a1af5748 100644 --- a/packages/image_picker/ios/Classes/FLTImagePickerImageUtil.m +++ b/packages/image_picker/ios/Classes/FLTImagePickerImageUtil.m @@ -31,57 +31,18 @@ @implementation FLTImagePickerImageUtil : NSObject + (UIImage *)scaledImage:(UIImage *)image maxWidth:(NSNumber *)maxWidth maxHeight:(NSNumber *)maxHeight { - double originalWidth = image.size.width; - double originalHeight = image.size.height; - - bool hasMaxWidth = maxWidth != (id)[NSNull null]; - bool hasMaxHeight = maxHeight != (id)[NSNull null]; - - double width = hasMaxWidth ? MIN([maxWidth doubleValue], originalWidth) : originalWidth; - double height = hasMaxHeight ? MIN([maxHeight doubleValue], originalHeight) : originalHeight; - - bool shouldDownscaleWidth = hasMaxWidth && [maxWidth doubleValue] < originalWidth; - bool shouldDownscaleHeight = hasMaxHeight && [maxHeight doubleValue] < originalHeight; - bool shouldDownscale = shouldDownscaleWidth || shouldDownscaleHeight; - - if (shouldDownscale) { - double downscaledWidth = floor((height / originalHeight) * originalWidth); - double downscaledHeight = floor((width / originalWidth) * originalHeight); - - if (width < height) { - if (!hasMaxWidth) { - width = downscaledWidth; - } else { - height = downscaledHeight; - } - } else if (height < width) { - if (!hasMaxHeight) { - height = downscaledHeight; - } else { - width = downscaledWidth; - } - } else { - if (originalWidth < originalHeight) { - width = downscaledWidth; - } else if (originalHeight < originalWidth) { - height = downscaledHeight; - } - } - } - - // Scaling the image always rotate itself based on the current imageOrientation of the original - // Image. Set to orientationUp for the orignal image before scaling, so the scaled image doesn't - // mess up with the pixels. - UIImage *imageToScale = [UIImage imageWithCGImage:image.CGImage - scale:1 - orientation:UIImageOrientationUp]; - - UIGraphicsBeginImageContextWithOptions(CGSizeMake(width, height), NO, 1.0); - [imageToScale drawInRect:CGRectMake(0, 0, width, height)]; - - UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext(); - UIGraphicsEndImageContext(); - return scaledImage; + NSData *imageData = UIImagePNGRepresentation(image); + CGImageSourceRef src = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL); + CFDictionaryRef options = (__bridge CFDictionaryRef) @{ + (id)kCGImageSourceCreateThumbnailWithTransform : @YES, + (id)kCGImageSourceCreateThumbnailFromImageAlways : @YES, + (id)kCGImageSourceThumbnailMaxPixelSize : MAX(maxWidth, maxHeight) + }; + + CGImageRef scaledImageRef = CGImageSourceCreateThumbnailAtIndex(src, 0, options); + UIImage *scaled = [UIImage imageWithCGImage:scaledImageRef]; + CGImageRelease(scaledImageRef); + return scaled; } + (GIFInfo *)scaledGIFImage:(NSData *)data diff --git a/packages/image_picker/pubspec.yaml b/packages/image_picker/pubspec.yaml index c5d1647bb410..ad09895d9445 100755 --- a/packages/image_picker/pubspec.yaml +++ b/packages/image_picker/pubspec.yaml @@ -5,7 +5,7 @@ authors: - Flutter Team - Rhodes Davis Jr. homepage: https://github.com/flutter/plugins/tree/master/packages/image_picker -version: 0.6.1+4 +version: 0.6.1+5 flutter: plugin: