2010-05-14 105 views
1

我成功实施了一款适用于ipad以及iphone的应用程序。 在我提供的选项给用户发送应用程序的屏幕截图作为邮件附件。即使这样运作良好。 但我的代码正在采取屏幕截图,无论方向如何。我得到的图像始终处于肖像模式。 我想根据ipad/iphone的方向拍摄屏幕截图并将图像作为附件发送。我正在使用以下代码拍摄屏幕截图。iphone/ipad应用程序 - 拍摄屏幕截图

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

回答

2

有哈代马西亚在实施类别:

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

它有一堆的UIImage的类别。 要使用的一个是:

UIimage* newImage = [imageToBeRotated imageRotatedByDegrees:90.0]; 

你的角度将取决于你的设备的当前方位。 使用:

[[UIApplication sharedApplication] statusBarOrientation] 

获取设备的方向。

希望这会有所帮助。

0

除了已经旋转的实际窗口之外,可能会有顶层视图可以渲染。如果您显示状态栏,请尝试获取该状态的超级视图。否则,这样的事情可能工作:

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); 
} 

... 

你可能会与CGContextTranslateCTM有勾搭,但它应该是接近。