My newest application, Image Shadow Adder, adds a shadow to an image. I plan on using this instead of Photoshop to restore shadows to my window screenshots (OS X's window screenshot command, ⇪⇧⌘4, does not preserve the shadow).
Also, the source code (BSD license) demonstrates how to use Bindings (used to insert the original and shadowed images into the document window's image views), use NSShadow, and capture an NSImage to an NSBitmapImageRep. Few comments in the code, I'm sorry to say, as this is just a quick-and-dirty application that I wrote when it dawned on me that I could use NSShadow when drawing an NSImage, rather than emulating my old Photoshop technique.
For reference, that technique was:
- Take one regular window screenshot, and one rectangular screenshot of the window with shadow on a white background.
- Drag and drop the window screenshot into the rectangular screenshot. Position so that the two window images line up.
- Knock out the black corners on the window screenshot. These are masked out by the alpha channel in the PNG file, but Photoshop sucks at alpha channels.
- Create a new layer. Fill with black.
- Load the window screenshot as a selection.
- Add a layer mask (reveal selection) to the black layer.
- Copy Merged.
- Add an alpha channel. Paste into it, and invert it. The area of the window should be white, with the shadow fading to black.
- Return to the Layers list and disable or delete the layer mask. Move the black layer down beneath the window-screenshot layer.
- Export using SuperPNG.