2013-09-27 40 views
0

如何截取UIView中选定框架的屏幕截图并将其设置为UIImage?在UIView中截取选定框架的屏幕截图

我也试过这个

UIGraphicsBeginImageContext(CGSizeMake(width,height)); 
CGContextRef context = UIGraphicsGetCurrentContext(); 
[imageview.layer renderInContext:context]; 
UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
+0

更改您的上下文是你想要捕捉的UIView的背景下。 – FaddishWorm

+0

检查http://stackoverflow.com/questions/8702834/programmatically-take-a-screenshot-of-specific-area – iPatel

回答

0

你可以像这样

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