0

While developing a photography based app i need to rotate an image. But after rotating an image it's border gets fuzzy. i have attached screen shot of this..

enter image description here

As you can see first image looks good but other images which are rotated are not looking good.

here is my code.....

        [img setBackgroundColor:[UIColor blackColor]];
        [img setContentMode:UIViewContentModeScaleAspectFit];
        [img.layer setBorderColor:[[UIColor whiteColor]CGColor]];
        [img.layer setBorderWidth:3.0];
        [img setTransform:CGAffineTransformMakeRotation(rotation*3.14/180)];

I have used this solution...

CGContextRotateCTM(context, radians);
[sourceImage drawInRect:rect];

But how to work with this code when image has boarders.

Please give your valuable response .....

Nirav Gadhiya
  • 6,342
  • 2
  • 37
  • 76

2 Answers2

1

When you rotate an image the border pixels are not antialiased: See this question.

The solution, as odd as it sounds, is to give the image a 1px transparent border. This answer gives the code to add the 1px transparent border to your image.

Community
  • 1
  • 1
Pliskin
  • 1,259
  • 10
  • 11
0

Its because of aliasing effect. Search for "anti-aliasing".

m177312
  • 1,199
  • 2
  • 14
  • 22