本文介绍了cameraOverlayView在UIImagePickerController中裁剪结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用 UIImagePickerController
和 cameraOverlayView
时,我可以从叠加视图中获得唯一的选区吗? / p>
解决方案
- 将UIImageView作为子项添加到cameraOverlayView。
- 创建黑色PNG图像大小320x480。在中间切一个矩形以产生一个洞(透明像素)。
- 将PNG图像分配给UIImageView。
或者你可以覆盖你的cameraOverlayView的 - (void)drawRect:(CGRect)rect
就像这样(我的头脑中未经测试):
//请求绘制上下文
CGContextRef context = UIGraphicsGetCurrentContext();
//绘制背景
CGContextSetRGBFillColor(context,0.0f,0.0f,0.0f,1.0f);
CGContextFillRect(context,rect);
//切洞
CGContextSetBlendMode(context,kCGBlendModeClear);
CGContextFillRect(context,CGRectMake(40,40,100,100);
我有在我的Faces应用程序中做了类似的事情()。随意如果其中一个步骤似乎不清楚,请写评论。
When I use UIImagePickerController
with cameraOverlayView
, can I get the only a selective region from my overlay view?
解决方案
- Add an UIImageView as child to your cameraOverlayView.
- Create a black PNG image size 320x480. Cut a rectangle in the middle to produce a hole (transparent pixels).
- Assign the PNG image to the UIImageView.
Alternatively you could overwrite your cameraOverlayView's - (void)drawRect:(CGRect)rect
like this (untested out of my head):
// Request draw context
CGContextRef context = UIGraphicsGetCurrentContext();
// Draw background
CGContextSetRGBFillColor(context, 0.0f, 0.0f, 0.0f, 1.0f);
CGContextFillRect(context, rect);
// Cut hole
CGContextSetBlendMode(context, kCGBlendModeClear);
CGContextFillRect(context, CGRectMake(40, 40, 100, 100);
I have done something similar in my Faces app (http://faces.pixelshed.net/). Feel free to write a comment if one of the steps seems unclear.
这篇关于cameraOverlayView在UIImagePickerController中裁剪结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!