I've got a UIImageView (full frame and rectangular) that i'm rotating with a CGAffineTransform. The UIImage of the UIImageView fills the entire frame. When the image is rotated and drawn the edges appear noticeably jagged. Is there anything I can do to make it look better? It's clearly not being anti-aliased with the background.
+4
A:
Remember to set the appropriate anti-alias options:
CGContextSetAllowsAntialiasing(theContext, true);
CGContextSetShouldAntialias(theContext, true);
Nathan de Vries
2009-07-16 12:23:46
I'm not seeing any difference when adding these Antialiasing lines to enclosing the UIImageView's drawRect...as well as the enclosing superview's. Even tried: CGContextSetInterpolationQuality(context, kCGInterpolationHigh); to no avail... When the UIImageView rect gets transformed (rotated) the edges are always jaggy..
Meltemi
2009-11-04 09:03:45
Best way to solve that problem is by adding a 1px transparent border to your image prior to rotation.
Nathan de Vries
2009-11-04 11:48:01
The 1px transparent border did the trick!
Meltemi
2010-02-11 16:13:47
How would you add the transparent border? I'm have the same issue while rotating a CALayer with perspective.
Brian
2010-04-23 18:01:51
A:
I would totally recommend the following library.
http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/
It contains lots of useful extensions to UIImage that solve this problem and also include code for generating thumbnails etc.
Enjoy!
Sway
2010-02-11 01:59:39