2013-09-27 104 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()