2013-03-03 159 views
1

我捕捉畫面的一部分,所述應用程序當前正在使用以下代碼表示當丟失的質量:捕獲屏幕

UIGraphicsBeginImageContext(self.view.bounds.size); 
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *sourceImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

UIGraphicsBeginImageContext(CGSizeMake(320, 320)); 
[sourceImage drawAtPoint:CGPointMake(0, -45)]; 
UIImage *croppedImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

問題是,比較到原來的畫面時,結果具有降低的質量。 如何防止質量損失?

+0

檢查這個帖子http://stackoverflow.com/questions/13832871/resolution-of-capture-screen-image-is-not-retina – 2013-03-03 12:36:09

回答

4

爲您的信息。

// Create a graphics context with the target size 
// On iOS 4 and later, use UIGraphicsBeginImageContextWithOptions to take the scale into consideration 
// On iOS prior to 4, fall back to use UIGraphicsBeginImageContext 
CGSize imageSize = [[UIScreen mainScreen] bounds].size; 
if (NULL != UIGraphicsBeginImageContextWithOptions) 
    UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0); 
else 
    UIGraphicsBeginImageContext(imageSize); 

CGContextRef context = UIGraphicsGetCurrentContext(); 
+0

太好了!簡單而且很好的解釋! – 2013-04-02 05:11:42