IOS UIImage图像颠倒

如果我画我的图片我修复了问题使用CGAffintrasform

CGAffineTransform myTr = CGAffineTransformMake(1, 0, 0, -1, 0, backImage.size.height); CGContextConcatCTM(context, myTr); [backImage drawInRect:CGRectMake(cbx, -cby, backImage.size.width, backImage.size.height)]; myTr = CGAffineTransformMake(1, 0, 0, -1, 0, backImage.size.height); CGContextConcatCTM(context, myTr); 

当我想写入文件我使用这个

  NSData *imageData = UIImageJPEGRepresentation(backImage, 0); 

那么图像倒过来怎么样?

当你想得到一个UIImage保存,使用:

 UIGraphicsBeginImageContextWithOptions(size, isOpaque, 0); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextDrawImage(context, (CGRect){ {0,0}, origSize }, [origImage CGImage]); UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; 

然后做:

  NSData *imageData = UIImageJPEGRepresentation(backImage, 0); 

首先制作标识matrix。

 1, 0, 0 0, 1, 0 0, 0, 1 CGAffineTransform matrix = CGAffineTransformMake(1, 0, 0, 1, 0, 0); 

移动绘图位置…

 matrix = CGAffineTransformTranslate(matrix, x, y); 

水平翻转matrix。

 matrix = CGAffineTransformScale(matrix, -1, 1); 

翻转matrix垂直。

 matrix = CGAffineTransformScale(matrix, 1, -1); 

旋转matrix

 matrix = CGAffineTransformRotate(matrix, angle); 

将UIImage缩放到UIView。

 matrix = CGAffineTransformScale(matrix, imageWidth/viewWidth, imageheight/viewHeight); 

在上下文中启动matrix。

 CGContextConcatCTM(context, matrix); 

绘制图像。

 [backImage drawAtPoint:CGPointMake(0, 0)]; 

🙂