Merge pull request #3321 from ty0x2333/fix_scale_down_image
Fix #3320 `decodedAndScaledDownImageWithImage` does not render the image completely
This commit is contained in:
commit
81ea1c9a9c
|
@ -448,7 +448,7 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
|
||||||
float dify = destTile.size.height;
|
float dify = destTile.size.height;
|
||||||
destTile.size.height = CGImageGetHeight( sourceTileImageRef ) * imageScale;
|
destTile.size.height = CGImageGetHeight( sourceTileImageRef ) * imageScale;
|
||||||
dify -= destTile.size.height;
|
dify -= destTile.size.height;
|
||||||
destTile.origin.y += dify;
|
destTile.origin.y = MIN(0, destTile.origin.y + dify);
|
||||||
}
|
}
|
||||||
CGContextDrawImage( destContext, destTile, sourceTileImageRef );
|
CGContextDrawImage( destContext, destTile, sourceTileImageRef );
|
||||||
CGImageRelease( sourceTileImageRef );
|
CGImageRelease( sourceTileImageRef );
|
||||||
|
|
|
@ -96,6 +96,25 @@
|
||||||
expect(decodedImage.size.height).to.equal(1);
|
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 {
|
- (void)test08ThatEncodeAlphaImageToJPGWithBackgroundColor {
|
||||||
NSString *testImagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestImage" ofType:@"png"];
|
NSString *testImagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestImage" ofType:@"png"];
|
||||||
UIImage *image = [[UIImage alloc] initWithContentsOfFile:testImagePath];
|
UIImage *image = [[UIImage alloc] initWithContentsOfFile:testImagePath];
|
||||||
|
|
Loading…
Reference in New Issue