2013-01-11 573 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?