diff --git a/SDWebImage/Core/SDImageCoderHelper.m b/SDWebImage/Core/SDImageCoderHelper.m index 6b9d650b..0d5fe45d 100644 --- a/SDWebImage/Core/SDImageCoderHelper.m +++ b/SDWebImage/Core/SDImageCoderHelper.m @@ -721,7 +721,7 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over sourceTileImageRef = CGImageCreateWithImageInRect( sourceImageRef, sourceTile ); if( y == iterations - 1 && remainder ) { float dify = destTile.size.height; - destTile.size.height = CGImageGetHeight( sourceTileImageRef ) * imageScale; + destTile.size.height = CGImageGetHeight( sourceTileImageRef ) * imageScale + kDestSeemOverlap; dify -= destTile.size.height; destTile.origin.y = MIN(0, destTile.origin.y + dify); } diff --git a/Tests/Tests/SDImageCoderTests.m b/Tests/Tests/SDImageCoderTests.m index 55364cdc..167d1c4a 100644 --- a/Tests/Tests/SDImageCoderTests.m +++ b/Tests/Tests/SDImageCoderTests.m @@ -96,11 +96,13 @@ expect(decodedImage.size.height).to.equal(1); } -- (void)test07ThatDecodeAndScaleDownAlwaysCompleteRendering { +-(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. + // Check that when the height of the image used will led to loss of precision. the output image can also be rendered completely, + UIColor *imageColor = UIColor.blackColor; - CGSize imageSize = CGSizeMake(3024, 4032); + CGSize imageSize = CGSizeMake(1029, 1029); CGRect imageRect = CGRectMake(0, 0, imageSize.width, imageSize.height); SDGraphicsImageRendererFormat *format = [[SDGraphicsImageRendererFormat alloc] init]; format.scale = 1; @@ -110,9 +112,11 @@ 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); + UIImage *decodedImage = [UIImage sd_decodedAndScaledDownImageWithImage:image limitBytes:1 * 1024 * 1024]; + UIColor *testColor1 = [decodedImage sd_colorAtPoint:CGPointMake(0, decodedImage.size.height - 1)]; + UIColor *testColor2 = [decodedImage sd_colorAtPoint:CGPointMake(0, decodedImage.size.height - 9)]; + expect(testColor1.sd_hexString).equal(imageColor.sd_hexString); + expect(testColor2.sd_hexString).equal(imageColor.sd_hexString); } - (void)test08ThatEncodeAlphaImageToJPGWithBackgroundColor {