Add shadow to PNG using Cocoa

I have several PNGs with a transparent background in which I would like to add shadows programmatically. I saw examples of adding shadows to square objects, but I did not see complex shapes.

So the two steps that I think I would have to take are:

  • Isolate PNG Form
  • Draw a shape behind PNG that is blurry, darkened and offset.

I do not have much experience in drawing in Cocoa, so any understanding of where to start will be much appreciated!

Screenshot: alt text
(source: iworkinprogress.com )

+4
source share
4 answers

The easiest way is to call CGContextSetShadow in drawRect: before drawing images.

 - (void)drawRect:(CGRect)invalidRect { CGContextRef c = UIGraphicsGetCurrentContext(); CGContextSetShadow(c, CGSizeMake(5.0f, 5.0f), 5.0f); [myImage drawAtPoint:CGPointMake(50.0f, 50.0f)]; } 
+3
source

I found this category very useful: UIImage + Shadow.m

https://gist.github.com/kompozer/387210

+1
source

I am not a graphic character, but what about this: if you have a mask for these images or you can create it programmatically, then you can use the blur function to add a shadow effect.

Experiment in Photoshop / Acorn / Pixelmator?

0
source

Since you want the shadows, like all of them, to have the same light source ... it looks like you really could be better off with an OpenGL view that emits light from above, and the images will sit just above a flat plane so that cast a shadow on. I would look for 3D OpenGL frameworks that would allow you to easily add things ...

0
source

Source: https://habr.com/ru/post/1299834/


All Articles