从UITextView中获取图像
我有一个只包含文本的UITextView,我想从中获取一个快照。 我以编程方式创build它。
UITextView *textView = [[UITextView alloc] init];
如果UITextView的背景颜色是黑色的,而文本颜色是白色的,我想分析每个像素来知道我是在白色还是黑色像素上。
如何做快照从UITextView获取图像(只有可能的话)?
作为UIView类别实现这个方法,你可以绘制任何UIView作为图像:
- (UIImage*)drawAsImage { // setup context UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0f); // use same scale factor as device CGContextRef c = UIGraphicsGetCurrentContext(); // render view [self.layer renderInContext:c]; // get reslting image UIImage *result = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return result; }
你可以使用下面的方法来截图。
-(UIImage *) screenshot { CGRect rect; rect=yourTextView.Frame; UIGraphicsBeginImageContext(rect.size); CGContextRef context=UIGraphicsGetCurrentContext(); [self.view.layer renderInContext:context]; UIImage *image=UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; }
对的,这是可能的。 您可以使用此方法获取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];
- 如何更改标签栏项目的文字颜色
- 呼叫接收到接收器播放声音
- identifierForVendor和iOS6
- Firebase pod安装 – pod“Firebase /数据库” – 要求更高的最低部署目标
- 如果我以后使用SKTextureAtlas,Sprite Kit会多次加载纹理图集吗?
- 表格视图单元格加载animation一个接一个
- 如何使用核心数据执行插入/更新
- SceneKit,SCNMaterial的翻转方向
- 方法captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer :( CMSampleBufferRef)sampleBuffer fromConnection只调用了几次