Skip to content

Commit 69c70d8

Browse files
authored
fix: [iOS] Image is being resized up instead of down & Error "User did not grant library permission." in Android 10 (#2103)
* fix: [iOS] Image is being resized up instead of down * Fix: Error "User did not grant library permission." in Android 10
1 parent 6ff41ff commit 69c70d8

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

android/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</queries>
99

1010
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
11-
android:maxSdkVersion="28" />
11+
android:maxSdkVersion="29" />
1212

1313
<application>
1414

ios/src/Compression.m

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,28 @@ - (ImageResult*) compressImageDimensions:(UIImage*)image
4040

4141
CGFloat oldWidth = image.size.width;
4242
CGFloat oldHeight = image.size.height;
43+
44+
CGFloat widthScale = maxWidth / oldWidth;
45+
CGFloat heightScale = maxHeight / oldHeight;
46+
CGFloat scaleFactor = MIN(widthScale, heightScale);
47+
48+
CGFloat newWidth = oldWidth * scaleFactor;
49+
CGFloat newHeight = oldHeight * scaleFactor;
4350

44-
int newWidth = 0;
45-
int newHeight = 0;
46-
47-
if (maxWidth < maxHeight) {
48-
newWidth = maxWidth;
49-
newHeight = (oldHeight / oldWidth) * newWidth;
50-
} else {
51-
newHeight = maxHeight;
52-
newWidth = (oldWidth / oldHeight) * newHeight;
53-
}
5451
CGSize newSize = CGSizeMake(newWidth, newHeight);
55-
56-
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:newSize];
52+
53+
UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
54+
format.scale = image.scale;
55+
56+
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:newSize format:format];
5757
UIImage *resizedImage = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
5858
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
5959
}];
6060

61-
result.width = [NSNumber numberWithFloat:newWidth];
62-
result.height = [NSNumber numberWithFloat:newHeight];
61+
result.width = @(newWidth);
62+
result.height = @(newHeight);
6363
result.image = resizedImage;
64+
6465
return result;
6566
}
6667

0 commit comments

Comments
 (0)