title: Need to retain quality of image when rotating that image in iPhone
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/13814544/need-to-retain-original-quality-of-image-while-rotating-in-iphone-sdk">Need to retain original quality of image while rotating in iPhone sdk</a>  </p>
  </blockquote>
  
  
  
  <p>In my app, I can rotate an image by 90 degrees. When I rotate a number of times... it is getting blurred (pixel clarity is missing). I lost the img quality. Can anyone suggest way to implement this.</p>
  
  <p>Here I used a button to rotate the image. The code used for Rotation is:</p>
  
  <pre><code>- (UIImage *)rotateImage:(UIImage *) img
  {
  
       CGRect rect = CGRectMake(0, 0, img.size.width, img.size.height);
       UIGraphicsBeginImageContext(rect.size);
  
       CGContextRef context = UIGraphicsGetCurrentContext();
  
  
       if (img.imageOrientation == UIImageOrientationRight) 
       {
            CGContextRotateCTM (context, M_PI_2);
       } 
  
       else if (img.imageOrientation == UIImageOrientationLeft) 
       {
            CGContextRotateCTM (context, -(M_PI_2));
       }
  
       else if (img.imageOrientation == UIImageOrientationDown) 
       {
            // NOTHING
       } 
  
       else if (img.imageOrientation == UIImageOrientationUp) 
       {
           CGContextRotateCTM (context, M_PI_2);
       }
  
       //CGContextRotateCTM(context, M_PI_2);
  
       CGContextTranslateCTM(context,0, -(img.size.width));
       [img drawInRect:CGRectMake(0, 0, img.size.height,img.size.width)];
  
  
       UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
       appDelegate.savedImage=newImage;
  
       UIGraphicsEndImageContext();
       CGContextRelease(context);
       return newImage;
       }
  </code></pre>
  
  <p>Thanks in Advance.</p>