cameraOverlayView to crop the result in UIImagePickerController

拜拜、爱过 提交于 2019-12-20 15:28:56

问题


When I use UIImagePickerController with cameraOverlayView, can I get the only a selective region from my overlay view?

http://tinyurl.com/2fqy9nq


回答1:


  1. Add an UIImageView as child to your cameraOverlayView.
  2. Create a black PNG image size 320x480. Cut a rectangle in the middle to produce a hole (transparent pixels).
  3. 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.



来源:https://stackoverflow.com/questions/3545362/cameraoverlayview-to-crop-the-result-in-uiimagepickercontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!