2010-05-14 86 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有勾搭,但它應該是接近。