Multiple Clipped Rects to Create Collage in Core Graphics

断了今生、忘了曾经 提交于 2019-12-02 19:48:06

CGContextClipToRect intersects the current clipping rectangle with the argument provided. So the second time you call it, you are effectively turning your clipping region to nothing.

There is no way to restore the clipping region without restoring the graphics state. So, make a call to CGContextSaveGState at the top of your loop and a call to CGContextRestoreGState at the bottom.

The upside-down part can be fixed by adjusting the current transformation matrix: call CGContextTranslateCTM to move the origin and then CGContextScaleCTM to flip the y-axis.

The upside down image can be corrected by calling the below method :

CGImageRef flip (CGImageRef im) {
CGSize sz = CGSizeMake(CGImageGetWidth(im), CGImageGetHeight(im));
UIGraphicsBeginImageContextWithOptions(sz, NO, 0);
CGContextDrawImage(UIGraphicsGetCurrentContext(),
                   CGRectMake(0, 0, sz.width, sz.height), im);
CGImageRef result = [UIGraphicsGetImageFromCurrentImageContext() CGImage];
UIGraphicsEndImageContext();
return result;

}

Take help from below code as to where u will put this code:

UIGraphicsBeginImageContextWithOptions(CGSizeMake(leftRect.size.width, leftRect.size.height), NO, 0);
CGContextRef con = UIGraphicsGetCurrentContext();
CGContextDrawImage(con, leftRect,flip(leftReference));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!