2

I have a little advanced question I want to make a custom shape blur on a png image that is half transparent and the png has transparent areas , and then drawing a stroke around the image (avoiding the transparent area in png image). I tried using GPUImage for making blue over image but I get blocked at drawing a stroke around the non-transparent part of the image . I tried using this method (https://stackoverflow.com/a/15010886/4641980) But the stroke is half transparent (following the fact that the image non-transparent part is half transparent ).

I need your help to make this done . This example is nearly what i mean

https://i.stack.imgur.com/YdITu.png

I have spent alot of time searching and trying but so far in vain , I will be so thankful for your help . Thank you.

Community
  • 1
  • 1
Aproram
  • 348
  • 1
  • 3
  • 16
  • if the shape of blur image is fixed, you can mask the blur image via "CAShapeLayer". "CAShapeLayer" has strock property. – Blind Ninja Jun 16 '15 at 11:11
  • if you mean fixed path like fixed rectangle or circle , im afraid its not . its random like the shape in the link above . @HarvantS. – Aproram Jun 16 '15 at 13:34
  • that can be draw with CGPath or UIBezierPath (i prefer). Just use answered code with your path. Try once , you might get some help. The path could be static but unusual in shape. – Blind Ninja Jun 16 '15 at 13:36
  • @HarvantS. I have not worked with paths before but seems like i have to finally , I will do my search for using them and then combine your code , Thanks man for your help for advance . – Aproram Jun 16 '15 at 13:42
  • just try with simple shapes. For more complex shapes you can ask for a SVG image of shape and use that image in `PaintCode` tool. It will give you path from the SVG image. – Blind Ninja Jun 16 '15 at 13:43
  • 1
    Oh thats awesome , You saved me alot of time i was about to search for that . Thanks man, You are the best , (y) @HarvantS. – Aproram Jun 16 '15 at 16:12

1 Answers1

0

You can use "CAShapeLayer" to clip (or mask) the blur image. For this you need a CGPath of the masking (or clipping) shape.

CAShapeLayer *pathLayer = [CAShapeLayer layer];
pathLayer.frame=CGRectMake(-imageView.frame.origin.x, -imageView.frame.origin.y, imageView.frame.size.width, imageView.frame.size.height);
pathLayer.path = yourClippingPath.CGPath;
pathLayer.strokeColor = [[UIColor blackColor] CGColor];
pathLayer.fillColor = [[UIColor clearColor] CGColor];
pathLayer.lineWidth = 6.0;
pathLayer.lineJoin = kCALineJoinBevel;
[imageView.layer addSublayer:pathLayer];
Blind Ninja
  • 1,063
  • 13
  • 28
  • I Just Another Problem with clipping the path , The mask applied as a stroke not clipping whats inside the path , I explained the problem here , http://stackoverflow.com/q/30938134/4641980 I will be Thankful if You can help me with it , Thank you @Harvant S. – Aproram Jun 22 '15 at 16:33