【问题标题】:ios how to make a camera circle maskios如何制作相机圆圈蒙版
【发布时间】:2013-06-24 15:54:34
【问题描述】:

大家, 我想在相机上制作圆形蒙版。

我试试这个方法:

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

谢谢。

【问题讨论】:

标签: ios camera uiimagepickercontroller mask geometry


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:
    [[UIColor colorWithRed:0 green:0 blue:0 alpha:alpha/255.0] setStroke];
    

    设置你想要的 alpha 百分比

    【讨论】:

    • 谢谢!有任何其他方法可以做到这一点(相机上的圆形面具)。因为我的方法不好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-21
    • 2023-04-02
    • 1970-01-01
    • 2014-10-31
    • 2015-03-10
    • 2017-01-04
    相关资源
    最近更新 更多