TIP/Trick: How to use the Paint.NET PSD Plugin to manipulate PSD files from your C# application

Last week I found myself needing to retrieve some information from a Photoshop Document (PSD) file. Since this goes beyond the standard support of the IO .NET library I had to go around some loops and hoops to be able to achieve my goal. Here’s how I did it.

Paint.NET PSD Plugin

Being a Paint.NET user I’ve known about this plugin for a while now and have been using it to manage PSD files without having to install Photoshop. So I chose to use the library’s API to manipulate the PSD files with ease and I must say it worked like a charm.

Things you’ll need

  1. Paint.NET PSD Plugin. You can download this from the codeplex website.

  2. Paint.NET core dll's. You can retrieve this from your Paint.NET installation folder.

    image

  3. Add a reference to the Photoshop.dll from the Paint.NET PSD
    Plugin.

  4. Done!

Example code

    string[] psds = Directory.GetFiles(@"PATH_GOES_HERE", "*.psd", SearchOption.AllDirectories);            

    foreach (var psd in psds)
    {                
            var psdFile = new PsdFile();
            psdFile.Load(psd); // Loading the psd file

            // Printing the file name and the file dimensions (width/height)
            Console.WriteLine("{0}: {1}x{2}",
                    Path.GetFileName(psd),
                    psdFile.ColumnCount,
                    psdFile.RowCount);
    }

    Console.ReadKey();

That's all you need to edit or just retrieve info from PSD files. If you need to interact with the file in a more complex manner I would recommend reading through the documentation in order to learn if what you want to do is within the plugin’s scope.