Skip to content

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