how to get transparent view in round shape using CGContext

Discussion in 'iOS Programming' started by goldenlife, Oct 28, 2010.

  1. goldenlife macrumors newbie

    Joined:
    Oct 2, 2010
    #1
    HI ALL,

    I want to draw transparent view on touch event, i.e I can erase section of the UIImageView so that I can see what is behind the UIImageView.

    I am getting this but on touch, it erase the image in square shape,

    I want this in round shape.

    this is my code:

    UIGraphicsBeginImageContext(self.view.frame.size);
    [drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    CGContextSetShouldAntialias(UIGraphicsGetCurrentContext(), YES);
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    //CGContextSetLineCap(UIGraphicsGetCurrentContext(),kCGImageAlphaNone);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 15);

    CGContextSetAlpha(UIGraphicsGetCurrentContext(), 0);
    CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeNormal);// kCGBlendModeClear);
    CGContextSaveGState(UIGraphicsGetCurrentContext()); //Probably right here


    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(),
    lastPoint.x,
    lastPoint.y);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(),
    currentPoint.x,
    currentPoint.y);
    CGContextStrokePath(UIGraphicsGetCurrentContext());


    CGContextClearRect (UIGraphicsGetCurrentContext(), CGRectMake(lastPoint.x, lastPoint.y, 20, 20));
    drawImage.image = UIGraphicsGetImageFromCurrentImageContext();

    //
    This code works fine but it erase front Image in Square shape,
    How can I make it in round shape?
    can anybody help please?

    Thanks.
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    I think you need to look at clipping for the context. See Clipping to a Path in the Quartz 2D Programming guide.
     
  3. goldenlife thread starter macrumors newbie

    Joined:
    Oct 2, 2010
    #3
    Hi,

    thanks for your reply,
    can you please elaborate on this , how to use clipping context here,
    as I tried using clipping context, but still I am not getting round shape touch..

    what kind of change I do in my code?

    Please Help..
     

Share This Page