views:

1046

answers:

2

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
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
Best way to solve that problem is by adding a 1px transparent border to your image prior to rotation.
Nathan de Vries
The 1px transparent border did the trick!
Meltemi
How would you add the transparent border? I'm have the same issue while rotating a CALayer with perspective.
Brian
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