2010-08-11 181 views

回答

4

使用:

UIGraphicsBeginImageContext(rect.size); 
[webView.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
+0

当你采取一个web视图的截图,它只需要屏幕可见区域热。隐藏区域未被考虑在内。 – 2013-01-28 07:33:44

7

接受的答案是正确的,但截图是不是在视网膜的分辨率。 使用UIGraphicsBeginImageContextWithOptions并设置其比例参数0.0f使其以原始分辨率捕捉。

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(); 
3

使用此代码采取截图并保存到库

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

,你可以通过改变

UIGraphicsBeginImageContext(self.view.bounds.size); 

到您的相应值 尝试改变截图摄影部它会帮助你