C# 如何从 Photoshop 文件中提取图层?C#
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/499597/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to extract layers from a Photoshop file? C#
提问by pek
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)?
C# 中是否有一个库可以让我读取 photoshop 文件 (PSD) 中的图层并将它们提取为透明图像 (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).
Photoshop 有一个批处理命令,可以提取单个文件中的所有图层,但无法选择透明的 PNG。我的目标是创建一个小型实用程序,可以根据需要创建图层组合(例如,考虑创建卡片组)。
回答by Darin Dimitrov
回答by Joan Venge
You can do that with Photoshop COM.
您可以使用 Photoshop COM 做到这一点。
回答by Zian Choy
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:psdpluginfor more sample code that loads PSD files.
如果您没有安装 Photoshop,那么您可能需要查看http://frankblumenberg.de/doku/doku.php?id=paintnet:psdplugin上的代码,以获取更多加载 PSD 文件的示例代码。
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/.
不幸的是,我不知道有一个预先存在的 PNG 库可以满足您的需求,但是用于 PNG 文件操作的规范库代码位于http://www.libpng.org/pub/png/。
回答by Savvas Dalkitsis
I found a code samplethat does this in Java.
我找到了一个在 Java 中执行此操作的代码示例。
"Supports uncompressed or RLE-compressed RGB files only"
Also supports only older PSD versions :
也仅支持较旧的 PSD 版本:
"Does not support additional features in PS versions higher than 3.0"
Also ImageMagick handles PSD and has interfaces to many languages :
此外,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)"
回答by Orwellophile
ImagicMagick (which wasmentioned in the other SO article) does allow layers to be extracted separately. See: http://www.rubblewebs.co.uk/imagemagick/psd.php
ImagicMagick(这是其他SO文章中提到)确实允许层被分别提取。见: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
回答by Adam Mac
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.
我不得不下载 Frank Blumenberg 先生所做的 cs 文件(基于 Jonas Beckeman 的 Endogine 引擎),因为获得paintdotnet dll 本身是不够的。
I believe it was here that i got the cs files.
我相信是在这里我得到了 cs 文件。
http://code.google.com/p/skimpt/source/browse/trunk/Skimpt3/Skimpt3/classes/photoshop/?r=72
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.
这似乎也适用于 CS6 文件。
update: a vs2013 website is here: http://goo.gl/H6nWSN.
更新:vs2013 网站在这里:http: //goo.gl/H6nWSN。