diff --git a/SDWebImage/Core/SDImageCoderHelper.m b/SDWebImage/Core/SDImageCoderHelper.m index 321710b5..95a95000 100644 --- a/SDWebImage/Core/SDImageCoderHelper.m +++ b/SDWebImage/Core/SDImageCoderHelper.m @@ -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 ); diff --git a/Tests/Tests/SDImageCoderTests.m b/Tests/Tests/SDImageCoderTests.m index ee2614d6..199c92be 100644 --- a/Tests/Tests/SDImageCoderTests.m +++ b/Tests/Tests/SDImageCoderTests.m @@ -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];