从 UITextView 获取图像 [英] take image from UITextView

查看:38
本文介绍了从 UITextView 获取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个仅包含文本的 UITextView,我想从中获取快照.我以编程方式创建了它.

I have a UITextView containing text only and I want to take a snapshot from it. I created it programmatically.

UITextView *textView = [[UITextView alloc] init];

如果 UITextView 的背景色是黑色,文字色是白色,我想解析每个像素来知道我是在白色还是黑色像素上.

If the background color of the UITextView is black and the text color is white, I want to parse each pixel to know if I'm on the white or black pixel.

如何进行快照以从 UITextView 获取图像(仅在可能的情况下)?

How to do the snapshot to get an image from the UITextView (only if possible) ?

推荐答案

是的,这是可能的.您可以使用此方法拍摄文本视图的快照.

Yes it is possible. You can use this method for take the snapshot of the textview.

- (UIImage*)screenShotOfView:(UITextView *)view
{
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();


    return image;
}

并使用此代码调用方法

UITextView *textView = [[UITextView alloc] init];
[self screenShotOfView:textView];

这篇关于从 UITextView 获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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