BrunoLM
BrunoLM

Reputation: 100351

How can I get the layers from a PSD file?

I want to retrieve all layers from a PSD file and get their name, X and Y position.

Is there a C# Lib that can do that?

I've tried this lib from CodeProject, but I always get TargetInvokeException. My PSD files are from Photoshop CS5...


Exploring Paint.NET as Robin suggested I could get to this code:

var ps = new PsdFile();
ps.Load(file);
var name = ps.Layers[0].Name;
var xy = ps.Layers[0].Location;

I needed to include these references:

Upvotes: 8

Views: 6597

Answers (3)

Sprunth
Sprunth

Reputation: 744

0xA3 gives an answer in this thread. I've not personally used this library, but it seems like it is pretty simple and works well.

\Direct Copy\

The ImageMagick libraries (which provide bindings for C#) also support the PSD format. They might be easier to get started with than getting into the Paint.NET code and also come with a quite free (BSD-like) license.

A simple sample (found at http://midimick.com/magicknet/magickDoc.html) using MagickNet would look like this:

using System;

static void Main(string[] args)
{
    MagickNet.Magick.Init();
    MagicNet.Image img = new MagicNet.Image("file.psd");
    img.Resize(System.Drawing.Size(100,100));
    img.Write("newFile.png");
    MagickNet.Magick.Term();
}

Note: MagickNet has moved to http://www.codeproject.com/KB/dotnet/ImageMagick_in_VBNET.aspx

Upvotes: 2

Robin Orheden
Robin Orheden

Reputation: 2764

You could use the PSD-plugin for Paint.NET to do it.

Should be fairly easy to extract the parser library from there.

http://psdplugin.codeplex.com/

Upvotes: 4

Machinarius
Machinarius

Reputation: 3731

I dont have Photoshop installed so i dont know if this could work, but maybe either GIMP or Photoshop (or related software) export COM assemblies that you can use, just like the Office Suite does....

Hope this helps.

Upvotes: 0

Related Questions