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 scre开发者_如何学Cen 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();
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.
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;
}
UIGraphicsBeginImageContext(frame.size);
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.
精彩评论