IOS UIImage图像倒置



如果我画了我的图像,我使用CGAfintrasform解决了问题

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);

首先生成Identity矩阵。

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

移动绘图位置。。。

matrix = CGAffineTransformTranslate(matrix, x, y);

水平翻转矩阵。

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

垂直翻转矩阵。

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

旋转矩阵

matrix = CGAffineTransformRotate(matrix, angle);

将比例UIImage调整为UIView。

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

将矩阵放入上下文中。

CGContextConcatCTM(context, matrix);

绘制图像。

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

:)

最新更新