Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract layers from a Photoshop file? C#

Tags:

c#

photoshop

Is there a library in C# that will allow me to read the layers in a photoshop file (PSD) and extract them as transparent images (PNG)?

Photoshop has a batch command that will extract all layers in individual files but there is no choice of transparent PNGs. My goal is to create a small utility program that will create combinations of layers as you like (for example think of creating a card deck).

like image 283
pek Avatar asked Jan 31 '09 21:01

pek


3 Answers

There's a nice article on CodeProject which might be helpful. And here's a thread on SO discussing PSD file format parsing with C#.

like image 60
Darin Dimitrov Avatar answered Oct 08 '22 17:10

Darin Dimitrov


I couldnt find much on this anywhere, but this is how i ended up doing it.

using Photoshop;

Photoshop.PsdFile psd = new Photoshop.PsdFile();
psd.Load(pingTextsPsd);

for (int j = 0; j < psd.Layers.Count; j++)
            {
                System.Drawing.Image myPsdImage = ImageDecoder.DecodeImage(psd.Layers[j]);

                myPsdImage.Save(pingsOutputPath + psd.Layers[j].Name + ".png");

            }

i had to downloaded the cs files that Mr Frank Blumenberg did (based on the Endogine engine by Jonas Beckeman), as getting the paintdotnet dll itself wasnt enough.

I believe it was here that i got the cs files.

http://code.google.com/p/skimpt/source/browse/trunk/Skimpt3/Skimpt3/classes/photoshop/?r=72

This should allow you to get the layers..

:-)

This seems to work fine with CS6 files too.

update: a vs2013 website is here: http://goo.gl/H6nWSN.

like image 45
Adam Mac Avatar answered Oct 08 '22 18:10

Adam Mac


You can do that with Photoshop COM.

like image 22
Joan Venge Avatar answered Oct 08 '22 18:10

Joan Venge