[英]Taking a partial screenshot on the iPad
I'm trying to take a screenshot on save, but can only do full screen. 我正试图在保存时截取屏幕截图,但只能全屏显示。 Is there any way to take a partial screenshot?
有没有办法拍摄部分截图?
Here is a sample. 这是一个例子。 Say I just want to take a screenshot of the section highlighted in red.
假设我只想截取以红色突出显示的部分的屏幕截图。 Thanks for the help.
谢谢您的帮助。
http://img197.imageshack.us/img197/6499/sampleimagez.jpg http://img197.imageshack.us/img197/6499/sampleimagez.jpg
It looks like you want a screenshot of that web view there. 看起来你想要那个网页视图的截图。 If you want to get an image of a specific view and only that view (+ subviews), you can use the following code:
如果要获取特定视图的图像并仅获取该视图(+子视图),可以使用以下代码:
- (UIImage*)captureView:(UIView*)view
{
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(self.view.bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
Just pass the web view to that function and it should work. 只需将Web视图传递给该功能即可。
EDIT: 编辑:
Assuming that was just an example image and you want a screenshot of an area that is not contained in its own view, go with Canada Dev's solution. 假设这只是一个示例图像,并且您想要一个未包含在其自己视图中的区域的屏幕截图,请使用Canada Dev的解决方案。 Crop the image to the area that you want.
将图像裁剪到所需的区域。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.