Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS UIImage Image upside down

if i draw my image I fixed the problem use 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);

when i wanna write to file i use this

 NSData *imageData = UIImageJPEGRepresentation(backImage, 0);  

then Image upside down how ?

like image 292
zt9788 Avatar asked Jul 31 '12 12:07

zt9788


2 Answers

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);
like image 191
David H Avatar answered Sep 25 '22 02:09

David H


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

:)

like image 33
booiljoung Avatar answered Sep 25 '22 02:09

booiljoung