2012-01-23 119 views
0

我的問題是這樣的 -iPhone屏幕截圖轉換UIImageView

我有一個用戶可以自由旋轉的UIImageView。

我現在想要捕捉這個新旋轉的圖像。

下面的代碼可以截取單個視圖,但不幸返回 視圖在其未旋轉狀態下的屏幕截圖。

-(IBAction)captureScreen:(id)sender 
{ 
    UIGraphicsBeginImageContext(imgView.frame.size); 
    [imgView.layer renderInContext:UIGraphicsGetCurrentContext()]; 
    UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    UIImageWriteToSavedPhotosAlbum(screenshot, nil, nil, nil); 
} 

任何想法如何保留這裏的輪換?

+0

你可以把旋轉要實現什麼樣的代碼? –

回答

0

在包含旋轉視圖而不是旋轉視圖本身的視圖上使用您的代碼。

+0

感謝Simon,這部分工作 - 問題是,當imageView旋轉時,包含視圖不會增長以反映圖像視圖的新框架,從而產生裁剪的截圖。我覺得在這裏很愚蠢,因爲我似乎無法使包含視圖匹配旋轉的imageView的尺寸。我已經嘗試設置包含視圖的邊界和幀屬性動態imageview旋轉 - 但沒有喜悅......? –

+0

我嘗試通過使用self.view,仍然沒有喜悅的變焦視圖放大http://stackoverflow.com/questions/15574845/how-do-i-take-a-screenshot-of-a-view-which-我已經有了改變 – quantumpotato

0

試試這個嗎?

UIGraphicsBeginImageContext(self.view.bounds.size); 
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil); 
    NSString *yourPath; 
    NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:yourPath]; 
    [UIImageJPEGRepresentation(viewImage, 1.0) writeToFile:jpgPath atomically:YES]; 
0

我假設你通過UIImage方法旋轉圖像。問題在於它並不是真的在旋轉圖像本身,它只是告訴誰來繪製圖像。

我建議你只是實際使用核芯顯卡旋轉圖像,然後你可以保存結果的方式