ios如何制作相机圆形遮罩

ios如何制作相机圆形遮罩,ios,camera,uiimagepickercontroller,mask,geometry,Ios,Camera,Uiimagepickercontroller,Mask,Geometry,各位,, 我想在相机上做一个圆形遮罩 我试着这样做: - (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 th

各位,, 我想在相机上做一个圆形遮罩

我试着这样做:

- (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

谢谢

[[UIColor colorWithRed:0 green:0 blue:0 alpha:alpha/255.0] setStroke];

设置所需的alpha百分比

因为您没有提到可调整的圆形遮罩,我假设您需要在相机视图上设置一个静态圆形遮罩。如果您需要动态创建圆,这不是正确的答案。 无论如何,了解一种简单的方法可能会有所帮助:

准备一个实际上是圆形的png,圆形的内部是透明的。确保您可以处理适当的宽度和高度,甚至可以为不同的设备(如iPhone5和iPhone4)创建多个圆形png 使用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;

谢谢有没有其他方法可以在相机上画一个圆圈。因为我的方法不好。答案是: