2013-01-11 445 views

回答

4

嘗試使用全屏幕截圖下面的代碼(鍵窗口)

UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow]; 
CGRect rect = [keyWindow bounds]; 
UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f); 
CGContextRef context = UIGraphicsGetCurrentContext(); 
[keyWindow.layer renderInContext:context]; 
UIImage *capturedScreen = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

試試這個代碼捕獲一個UIView在原始分辨率

CGRect rect = [captureView bounds]; 
UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f); 
CGContextRef context = UIGraphicsGetCurrentContext(); 
[captureView.layer renderInContext:context]; 
UIImage *capturedImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

這節省了UIImage的在JPG格式與95%的質量在應用程序的文檔文件夾,如果你需要這樣做。

NSString *imagePath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/capturedImage.jpg"]];  
[UIImageJPEGRepresentation(capturedImage, 0.95) writeToFile:imagePath atomically:YES]; 

來源:How Do I Take a Screen Shot of a UIView?