Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix copyAssetsFileIOS's image resizing option to resize to exact width and height #975

Merged
merged 1 commit into from
Feb 28, 2021
Merged

Conversation

byeokim
Copy link
Contributor

@byeokim byeokim commented Jan 11, 2021

copyAssetsFileIOS accepts width and height and resizes image when copying from Camera Roll.

copyAssetsFileIOS(imageUri, destPath, width, height, scale, compression, resizeMode)

However currently it doesn't respect width and height, and copied image may or may not have width and height that match width and height. That's because copyAssetsFileIOS uses PHImageRequestOptionsResizeModeFast option which makes requestImageForAsset method efficiently resize the image to a size similar to, or slightly larger than, the target size.

BOOL useMaximumSize = CGSizeEqualToSize(size, CGSizeZero);
CGSize targetSize;
if (useMaximumSize) {
targetSize = PHImageManagerMaximumSize;
imageOptions.resizeMode = PHImageRequestOptionsResizeModeNone;
} else {
targetSize = CGSizeApplyAffineTransform(size, CGAffineTransformMakeScale(scale, scale));
imageOptions.resizeMode = PHImageRequestOptionsResizeModeFast;
}

This pull request changes the option from PHImageRequestOptionsResizeModeFast to PHImageRequestOptionsResizeModeExact which makes requestImageForAsset method resize the image to match the target size, i.e. width and height, exactly.

@itinance itinance merged commit 47cf330 into itinance:master Feb 28, 2021
@itinance
Copy link
Owner

Wow. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants