Fix the thumbnail pixel size calculation when preserveAspectRatio is true

This commit is contained in:
DreamPiggy 2022-06-12 16:32:33 +08:00
parent 91c9966d77
commit f90373ce14
2 changed files with 6 additions and 6 deletions

View File

@ -238,9 +238,9 @@ static NSString * kSDCGImageDestinationRequestedFileSize = @"kCGImageDestination
CGFloat pixelRatio = pixelWidth / pixelHeight;
CGFloat thumbnailRatio = thumbnailSize.width / thumbnailSize.height;
if (pixelRatio > thumbnailRatio) {
maxPixelSize = thumbnailSize.width;
maxPixelSize = MAX(thumbnailSize.width, thumbnailSize.width / pixelRatio);
} else {
maxPixelSize = thumbnailSize.height;
maxPixelSize = MAX(thumbnailSize.height, thumbnailSize.height * pixelRatio);
}
} else {
maxPixelSize = MAX(thumbnailSize.width, thumbnailSize.height);
@ -503,9 +503,9 @@ static NSString * kSDCGImageDestinationRequestedFileSize = @"kCGImageDestination
CGFloat pixelRatio = pixelWidth / pixelHeight;
CGFloat maxPixelSizeRatio = maxPixelSize.width / maxPixelSize.height;
if (pixelRatio > maxPixelSizeRatio) {
finalPixelSize = maxPixelSize.width;
finalPixelSize = MAX(maxPixelSize.width, maxPixelSize.width / pixelRatio);
} else {
finalPixelSize = maxPixelSize.height;
finalPixelSize = MAX(maxPixelSize.height, maxPixelSize.height * pixelRatio);
}
properties[(__bridge NSString *)kCGImageDestinationImageMaxPixelSize] = @(finalPixelSize);
}

View File

@ -257,9 +257,9 @@ static NSString * kSDCGImageDestinationRequestedFileSize = @"kCGImageDestination
CGFloat maxPixelSizeRatio = maxPixelSize.width / maxPixelSize.height;
CGFloat finalPixelSize;
if (pixelRatio > maxPixelSizeRatio) {
finalPixelSize = maxPixelSize.width;
finalPixelSize = MAX(maxPixelSize.width, maxPixelSize.width / pixelRatio);
} else {
finalPixelSize = maxPixelSize.height;
finalPixelSize = MAX(maxPixelSize.height, maxPixelSize.height * pixelRatio);
}
properties[(__bridge NSString *)kCGImageDestinationImageMaxPixelSize] = @(finalPixelSize);
}