7

如果我画我的图像我解决了问题使用 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);  

那么图像倒置怎么办?

4

2 回答 2

2

当您想要保存 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);
于 2012-07-31T14:00:17.507 回答
2

首先制作身份矩阵。

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

:)

于 2012-07-31T14:15:31.333 回答