IOS UIImage Image upside down

馋奶兔 提交于 2019-12-04 04:06:16

When you want to get a UIImage to save, use:

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

Then do:

 NSData *imageData = UIImageJPEGRepresentation(backImage, 0);
booiljoung

First make Identity matrix.

1, 0, 0
0, 1, 0
0, 0, 1

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

Move position for drawing...

matrix = CGAffineTransformTranslate(matrix, x, y);

Flip matrix horizontal.

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

Flip matrix vertical.

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

Rotate matrix

matrix = CGAffineTransformRotate(matrix, angle);

Fit scale UIImage to UIView.

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

Launch matrix into the context.

CGContextConcatCTM(context, matrix);

Draw image.

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

:)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!