1

How to save PSD layers in png using PSD-plugin for Paint.NET?

Trying to do this way:

System.Drawing.Image img;
var stream = new System.IO.MemoryStream();
var BRW = new PhotoshopFile.BinaryReverseWriter(stream);
var psd = new PhotoshopFile.PsdFile();
psd.Load("c:\\1.psd");
psd.Layers[0].Save(BRW);
stream.Seek(0, System.IO.SeekOrigin.Begin);
img = System.Drawing.Image.FromStream(stream, true, true);
img.Save("c:\\1.png", System.Drawing.Imaging.ImageFormat.Png);

But the line img = Image.FromStream(stream, true, true); throws "Parameter is not valid" exception.

Any other solutions via C#/C++ are also acceptable. Thanks in advance.

Nmk
  • 1,281
  • 2
  • 14
  • 25
kFk
  • 409
  • 6
  • 13
  • possible duplicate: http://stackoverflow.com/q/629955/635634. The most relevant answer to that question basically says your stream is corrupt. I doubt `System.Drawing.Image` understands psd format. – M.Babcock Jan 07 '12 at 21:32
  • Not a duplicate. I'm finding a solution for the problem, not the reason of error in wrong solution. – kFk Jan 07 '12 at 21:36

2 Answers2

0

The first solution does not work anymore with the latest version, use instead:

var psd = new PhotoshopFile.PsdFile("YourPhotoshop Path as string", Encoding.ASCII);

// or

var psd = new PhotoshopFile.PsdFile("Your Photoshop File Path as string", Encoding.Default);

Same with saving.

mhaenssgen
  • 31
  • 3
0

Have you thought about asking the author of the PSD plugin? Paint.NET isn't licensed for use as an SDK, by the way, only as an application.

Rick Brewster
  • 3,374
  • 1
  • 17
  • 21