Search code examples
iphoneipadscreenshotorientation

iphone/ipad application - taking screen shot


I successfully implemented an application that works on ipad as well as on iphone. In that I provided option to user to send the screen shot of the application as mail attachment. Even that is functioning well. But my code is taking screen shot irrespective of orientation. The image i'm getting is always in portrait mode. I want to take the screen shot depending on the orientation of ipad/iphone and send the image as attachment. I'm using following code to take the screen shot.

UIGraphicsBeginImageContext(screenWindow.frame.size);
[screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Solution

  • There is a category implemented by Hardy Macia at:

    http://www.catamount.com/forums/viewtopic.php?f=21&t=967

    It has a bunch of categories on UIImage. The one you want to be using is:

    UIimage* newImage = [imageToBeRotated imageRotatedByDegrees:90.0];
    

    Your angle will depend on the current orientation of your device. Use:

    [[UIApplication sharedApplication] statusBarOrientation]
    

    to get the orientation of your device.

    Hope this helps.