Search code examples
c#wpfphotoshopblend

Is it possible to programmatically manipulate a psd file's layers in WPF?


I have a Photoshop Document with a few layers that I can turn on and off to make the image display different data. Is it possible to place this image in a WPF page and use C# to turn on and off layers? I've been googling for a little while but there doesn't seem to be much information on this subject. I read that you might be able to use Expression Blend to do this, however I do not have any experience using it.
Any help would be greatly appreciated, thanks!


Solution

  • (Disclaimer: I'm a software engineer at Microsoft, I used to work on Expression Blend)

    In short, no. There is no built-in support for loading Photoshop files in the .NET Framework nor WPF (this is despite Blend's support for loading PSD documents into a project - it has its own code for this - and it doesn't support all of the features present in the PSD file format either).

    If you want to load a PSD file into your own program you'll need a PSD file reader - either write your own (a fool's errand considering how complicated the file format is) or obtain/license an existing library, there are open-source implementations available (see Paint.NET's).

    A problem with PSD files is that individual layers are not necessarily simple rasters by themselves, and PSD documents don't always contain a full-resolution composite either. Consider effects-layers (Brightness, Levels, etc) or layer-effects (Outer Glow, Gradient Overlay, etc).

    I suggest instead having Photoshop (via an Action or a Droplet program) convert your PSD's layers to individual PNG files (after applying any effects) and then loading those into your program and displaying them according to your requirements.