Skip to content

Commit

Permalink
Fix #1827 by flipping the context *properly* in UIImage draw.
Browse files Browse the repository at this point in the history
  • Loading branch information
DHowett committed Jan 27, 2017
1 parent 939705d commit bff7cce
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions Frameworks/UIKit/UIImage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -494,11 +494,16 @@ - (void)drawAtPoint:(CGPoint)point blendMode:(CGBlendMode)mode alpha:(float)alph
pos.size.height = (img_width / _scale);

srcRect.origin.x = 0;
srcRect.origin.y = img_height;
srcRect.origin.y = 0;
srcRect.size.width = img_width;
srcRect.size.height = -img_height;
srcRect.size.height = img_height;

_CGContextDrawImageRect(cur, img, srcRect, pos);
// |1 0 0| is the transformation matrix for flipping a rect about its Y midpoint m. (m = (y + h/2))
// |0 -1 0|
// |0 2m 1|
CGContextConcatCTM(cur, CGAffineTransformMake(1, 0, 0, -1, 0, 2 * (pos.origin.y + (pos.size.height / 2))));

CGContextDrawImage(cur, pos, img);
}

/**
Expand Down Expand Up @@ -545,6 +550,11 @@ static inline void drawPatches(CGContextRef context, UIImage* img, CGRect* dst)
const float dstLeftCap = img->_imageInsets.left;
const float dstRightCap = img->_imageInsets.right;

// |1 0 0| is the transformation matrix for flipping a rect about its Y midpoint m. (m = (y + h/2))
// |0 -1 0|
// |0 2m 1|
CGContextConcatCTM(context, CGAffineTransformMake(1, 0, 0, -1, 0, 2 * (dstY + (dstHeight / 2))));

// Center strip
if (dstHeight - dstTopCap - dstBotCap > 0) {
if (dstLeftCap) {
Expand Down

0 comments on commit bff7cce

Please sign in to comment.