Merge pull request #3321 from ty0x2333/fix_scale_down_image

Fix #3320 `decodedAndScaledDownImageWithImage` does not render the image completely
This commit is contained in:
DreamPiggy 2022-01-27 21:34:48 +08:00 committed by GitHub
commit 81ea1c9a9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -448,7 +448,7 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
float dify = destTile.size.height;
destTile.size.height = CGImageGetHeight( sourceTileImageRef ) * imageScale;
dify -= destTile.size.height;
destTile.origin.y += dify;
destTile.origin.y = MIN(0, destTile.origin.y + dify);
}
CGContextDrawImage( destContext, destTile, sourceTileImageRef );
CGImageRelease( sourceTileImageRef );

View File

@ -96,6 +96,25 @@
expect(decodedImage.size.height).to.equal(1);
}
- (void)test07ThatDecodeAndScaleDownAlwaysCompleteRendering {
// Check that when the height of the image used is not evenly divisible by the height of the tile, the output image can also be rendered completely.
UIColor *imageColor = UIColor.blackColor;
CGSize imageSize = CGSizeMake(3024, 4032);
CGRect imageRect = CGRectMake(0, 0, imageSize.width, imageSize.height);
SDGraphicsImageRendererFormat *format = [[SDGraphicsImageRendererFormat alloc] init];
format.scale = 1;
SDGraphicsImageRenderer *renderer = [[SDGraphicsImageRenderer alloc] initWithSize:imageSize format:format];
UIImage *image = [renderer imageWithActions:^(CGContextRef _Nonnull context) {
CGContextSetFillColorWithColor(context, [imageColor CGColor]);
CGContextFillRect(context, imageRect);
}];
UIImage *decodedImage = [UIImage sd_decodedAndScaledDownImageWithImage:image limitBytes:20 * 1024 * 1024];
UIColor *testColor = [decodedImage sd_colorAtPoint:CGPointMake(0, decodedImage.size.height - 1)];
expect(testColor.sd_hexString).equal(imageColor.sd_hexString);
}
- (void)test08ThatEncodeAlphaImageToJPGWithBackgroundColor {
NSString *testImagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestImage" ofType:@"png"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:testImagePath];