ios如何捕获屏幕的特定部分 [英] ios how to capture a particular portion of screen

查看:170
本文介绍了ios如何捕获屏幕的特定部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想拍摄iPhone屏幕的特定部分。我使用 UIGraphicsBeginImageContextWithOptions ,但无法用此捕获部分屏幕。
请帮助我。

I want to capture a particular portion of iPhone screen. I used UIGraphicsBeginImageContextWithOptions, but couldn't capture a portion of screen with this. Please help me.

推荐答案

您可以使用 UIGraphicsGetImageFromCurrentContext 。从内存中写下面的代码,因此可能出错。请自行更正。

You can take screen shot using UIGraphicsGetImageFromCurrentContext. Wrote below code from memory, so errors possible. Please correct it yourself.

- (UIImage*)captureView:(UIView *)yourView {
    CGRect rect = [[UIScreen mainScreen] bounds];
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [yourView.layer renderInContext:context];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

这篇关于ios如何捕获屏幕的特定部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆