Possible Duplicate:
Need to retain original quality of image while rotating in iPhone sdk
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.
Here I used a button to rotate the image. The code used for Rotation is:
- (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;
}
Thanks in Advance.