如何从 Photoshop 文件中提取图层? C#

发布于 2024-07-13 04:45:23 字数 170 浏览 8 评论 0 原文

C# 中是否有一个库可以让我读取 Photoshop 文件 (PSD) 中的图层并将它们提取为透明图像 (PNG)?

Photoshop 有一个批处理命令,可以提取单个文件中的所有图层,但无法选择透明 PNG。 我的目标是创建一个小型实用程序,它将根据您的喜好创建图层组合(例如,考虑创建一副卡片组)。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

旧瑾黎汐 2024-07-20 04:45:24

CodeProject 上有一篇不错的文章,可能会有所帮助。 这里有一个关于 SO 的 线程,讨论使用 C# 解析 PSD 文件格式。

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

梓梦 2024-07-20 04:45:24

我在任何地方都找不到太多关于这方面的信息,但这就是我最终做到的。

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

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.

抱着落日 2024-07-20 04:45:24

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

You can do that with Photoshop COM.

少年亿悲伤 2024-07-20 04:45:24

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

您可以使用命令行工具亲自尝试一下:

convert boots.psd[0] -thumbnail 340x340 boots_png.png

ImagicMagick (which was mentioned in the other SO article) does allow layers to be extracted separately. See: http://www.rubblewebs.co.uk/imagemagick/psd.php

You can try this for yourself using the command line tool:

convert boots.psd[0] -thumbnail 340x340 boots_png.png
你在看孤独的风景 2024-07-20 04:45:24

我找到了一个 代码示例,它在 Java 中执行此操作。

"Supports uncompressed or RLE-compressed RGB files only"

还仅支持较旧的 PSD 版本:

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

ImageMagick 还可以处理 PSD 并具有多种语言的接口:

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

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)"
沫离伤花 2024-07-20 04:45:24

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

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

If you don't have Photoshop installed, then you may want to look at the code at http://frankblumenberg.de/doku/doku.php?id=paintnet:psdplugin for more sample code that loads PSD files.

Unfortunately, I don't know of a pre-existing PNG library that does what you want but the canonical library code for PNG file manipulation is located at http://www.libpng.org/pub/png/.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文