如果我绘制我的图像,我使用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);
然后将图像颠倒了
怎么样?
答案 0 :(得分: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);
答案 1 :(得分: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)];
:)