7

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).

4

6 回答 6

4

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#.

于 2009-01-31T22:08:27.950 回答
4

我在任何地方都找不到太多,但这就是我最终这样做的方式。

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");

            }

我必须下载 Frank Blumenberg 先生所做的 cs 文件(基于 Jonas Beckeman 的 Endogine 引擎),因为获得paintdotnet dll 本身还不够。

我相信正是在这里我得到了cs文件。

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

这应该允许您获得图层..

:-)

这似乎也适用于 CS6 文件。

更新:vs2013 网站在这里:http: //goo.gl/H6nWSN

于 2013-01-21T12:09:30.833 回答
3

您可以使用 Photoshop COM 做到这一点。

于 2009-01-31T23:02:58.027 回答
1

ImagicMagick(在另一篇 SO 文章提到)确实允许单独提取层。见:http ://www.rubblewebs.co.uk/imagemagick/psd.php

您可以使用命令行工具自己尝试:

convert boots.psd[0] -thumbnail 340x340 boots_png.png
于 2011-12-29T06:58:48.113 回答
1

I found a code sample that does this in Java.

"Supports uncompressed or RLE-compressed RGB files only"

Also supports only older PSD versions :

"Does not support additional features in PS versions higher than 3.0"

Also ImageMagick handles PSD and has interfaces to many languages :

"Choose from these interfaces: G2F (Ada), MagickCore (C), MagickWand (C), ChMagick (Ch), ImageMagickObject (COM+), Magick++ (C++), JMagick (Java), L-Magick (Lisp), NMagick (Neko/Haxe), MagickNet (.NET), PascalMagick (Pascal), PerlMagick (Perl), MagickWand for PHP (PHP), IMagick (PHP), PythonMagick (Python), RMagick (Ruby), or TclMagick (Tcl/TK)"
于 2009-07-06T12:34:31.593 回答
0

如果您没有安装 Photoshop,那么您可能需要查看http://frankblumenberg.de/doku/doku.php?id=paintnet:psdplugin上的代码以获取更多加载 PSD 文件的示例代码。

不幸的是,我不知道现有的 PNG 库可以满足您的要求,但用于 PNG 文件操作的规范库代码位于http://www.libpng.org/pub/png/

于 2009-05-12T22:47:54.307 回答