Take the 2-minute tour ×

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.

[screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

There is a category implemented by Hardy Macia at:


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.

share|improve this answer
add comment

There may be a top level view you could render besides the actual window that is already rotated. If you are showing the status bar, try getting the superview of that. Otherwise something like this might work:

CGRect frame = screenWindow.frame;

if ( isLandscape ) {
  CGFloat t = frame.size.width;
  frame.size.width = frame.size.height;
  frame.size.height = t;


if ( isLandscape ) {
  CGContextRef context = UIGraphicsGetCurrentContext();
  CGContextRotateCTM( context , M_PI_2 );
  CGContextTranslateCTM( context , ( frame.size.width - frame.size.height ) * 0.5 ,
    ( frame.size.height - frame.size.width ) * 0.5 );


You will probably have to mess around with CGContextTranslateCTM but it should be close to that.

share|improve this answer
add comment

Your Answer


