在UIView中截取所选帧的屏幕截图

时间:2013-09-27 05:02:38

标签: iphone ios uiview screenshot

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

我也试过这个

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

1 个答案:

答案 0 :(得分:0)

你可以这样做

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