大家, 我想在相机上制作圆形遮罩。
我试试这种方式:
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextAddArc(context, self.frame.size.width/2, self.frame.size.height/2, 200, 0, M_PI *2, 0);
//Set the stroke color to black
[[UIColor blackColor]setStroke];
//Define line width and cap
CGContextSetLineWidth(context, 200);
CGContextSetLineCap(context, kCGLineCapButt);
//draw it!
CGContextDrawPath(context, kCGPathStroke);
}
只需设置足够大的线,但我认为它可以设置alpha。
感谢。
答案 0 :(得分:0)
[[UIColor colorWithRed:0 green:0 blue:0 alpha:alpha/255.0] setStroke];
设置您想要的alpha百分比
答案 1 :(得分:0)
由于您没有提到可调节圆形遮罩,我假设您需要在摄影机视图上使用静态圆形遮罩。如果您需要动态创建的圈子,这不是正确的答案。 无论如何,知道一种简单的方法可能会有所帮助:
使用imagePickerController的cameraOverlayView属性添加叠加图像
UIView *tmp_camera_overlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
UIImageView *tmp_camera_bkgr =[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"circle_screen_overlay.png"]];
tmp_camera_bkgr.frame = CGRectMake(0, 0, 320, 480);
[tmp_camera_overlay addSubview:tmp_camera_bkgr];
imagePickerController.cameraOverlayView = tmp_camera_overlay;