1

everybody, I want to make the circle mask on the camera.

i try this way:

- (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);
}

just set the line with enough big,but i think it can set alpha.

thanks.

seasunk
  • 31
  • 6
  • the answer is :http://stackoverflow.com/questions/15375777/cut-out-shape-with-animation/15377207#15377207 – seasunk Aug 02 '13 at 04:35

2 Answers2

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

set the alpha percent you want

adali
  • 5,977
  • 2
  • 33
  • 40
0

As you don't mentioned adjustable circle mask, I assume you need a static circle mask over on the camera view. If you need dynamically created circle, this is not the right answer. Anyway it might help to know a simple way to do this:

  • prepare a png which is a circle actually, and the inside of that circle is transparent (make sure you handle the proper width and height or even create multiple circle pngs for different devices eg. iPhone5 and iPhone4)
  • use the imagePickerController's cameraOverlayView property to add the overlay image

     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;
    
nzs
  • 3,252
  • 17
  • 22