C# 读取PSD文件格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/414852/
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
Reading PSD file format
提问by masfenix
I wonder if this is even possible. I have an application that adds a context menu when you right click a file. It all works fine but here is what I'd like to do:
我想知道这是否可能。我有一个应用程序,当您右键单击一个文件时,它会添加一个上下文菜单。一切正常,但这是我想要做的:
If the file is a PSD then I want the program to extract the image. Is this possible to do without having Photoshop installed?
如果文件是 PSD,那么我希望程序提取图像。这可以在没有安装 Photoshop 的情况下完成吗?
Basically I want the user to right click and click "image" which would save a .jpg of the file for them.
基本上我希望用户右键单击并单击“图像”,这将为他们保存文件的 .jpg。
edit: will be using c# Thanks
编辑:将使用 c# 谢谢
采纳答案by pkoperek
For people who are reading this now: the link from accepted answer doesn't seem to work anymore (at least for me). Would add a comment there, but not allowed to comment yet - hence I'm adding a new answer.
对于现在正在阅读本文的人:来自已接受答案的链接似乎不再起作用(至少对我而言)。会在那里添加评论,但还不允许发表评论 - 因此我要添加一个新答案。
The working link where you can find the psdplugin code for Paint.Net: https://github.com/PsdPlugin/PsdPlugin
您可以在其中找到 Paint.Net 的 psdplugin 代码的工作链接:https: //github.com/PsdPlugin/PsdPlugin
回答by Dave Markle
Well, there's a PSD plugin for Paint.NET which I think is Open-Source which you might want to take a look at for starters:
好吧,Paint.NET 有一个 PSD 插件,我认为它是开源的,你可能想看看初学者:
http://frankblumenberg.de/doku/doku.php?id=paintnet:psdplugin#download
http://frankblumenberg.de/doku/doku.php?id=paintnet:psdplugin#download
回答by Dirk Vollmar
The ImageMagicklibraries (which provide bindings for C#) also support the PSD format. They might be easier to get started with than getting into the Paint.NET code and also come with a quite free (BSD-like) license.
所述的ImageMagick库(其提供对于C#绑定)也支持PSD格式。它们可能比进入 Paint.NET 代码更容易上手,并且还附带一个非常免费的(类似 BSD 的)许可证。
A simple sample (found at http://midimick.com/magicknet/magickDoc.html) using MagickNet would look like this:
一个使用 MagickNet 的简单示例(可在http://midimick.com/magicknet/magickDoc.html 上找到)如下所示:
using System;
static void Main(string[] args)
{
MagickNet.Magick.Init();
MagicNet.Image img = new MagicNet.Image("file.psd");
img.Resize(System.Drawing.Size(100,100));
img.Write("newFile.png");
MagickNet.Magick.Term();
}
Note: MagickNet has moved to http://www.codeproject.com/KB/dotnet/ImageMagick_in_VBNET.aspx
注意:MagickNet 已移至http://www.codeproject.com/KB/dotnet/ImageMagick_in_VBNET.aspx
回答by Lazer
FastStone does this pretty efficiently. They do not have their libraries availaible, but I guess you can contact them and see if they can help.
FastStone 非常有效地做到了这一点。他们没有可用的图书馆,但我想您可以联系他们,看看他们是否可以提供帮助。
Check out their website: http://www.faststone.org/download.htm
查看他们的网站:http: //www.faststone.org/download.htm
回答by Franklin Albricias
This guy do it easier:
这家伙做起来更容易:
http://www.codeproject.com/KB/graphics/simplepsd.aspx
http://www.codeproject.com/KB/graphics/simplepsd.aspx
With a C# library and a sample project.
使用 C# 库和示例项目。
I've tried with PS2 files and works ok.
我已经尝试过使用 PS2 文件并且工作正常。
回答by qu1j0t3
I have written a PSD parser which extracts raster format layers from all versions of PSD and PSB. http://www.telegraphics.com.au/svn/psdparse/trunk
我编写了一个 PSD 解析器,它从所有版本的 PSD 和 PSB 中提取光栅格式层。http://www.telegraphics.com.au/svn/psdparse/trunk
回答by Orwellophile
ImageMagick.NET - http://imagemagick.codeplex.com/- is the later version of the link 0xA3 gave, with some slightly different syntax. (Note, this is untested):
ImageMagick.NET - http://imagemagick.codeplex.com/- 是 0xA3 给出的链接的更高版本,语法略有不同。(注意,这是未经测试的):
using ImageMagickNET;
public void Test() {
MagickNet.InitializeMagick();
ImageMagickNET.Image img = new ImageMagickNET.Image("file.psd");
img.Resize(new Geometry(100, 100, 0, 0, false, false);
img.Write("newFile.png");
}
回答by papirosnik
Here is my own psd parser and exporter: http://papirosnik.info/psdsplit/. It allows to correctly parse psd with rgb color 8, 16- and 32-bit for channel, process user masks, export selected layers into jpeg, png, jng, bmp, tiff; create xml layout of exported layers and groups and also create a texture atlas and animations set from given layers. It's entirely written in C#. If you want its sources inform me via support link on About dialog in the application.
这是我自己的 psd 解析器和导出器:http: //papirosnik.info/psdsplit/。它允许正确解析带有 rgb 颜色 8、16 和 32 位通道的 psd,处理用户蒙版,将所选图层导出为 jpeg、png、jng、bmp、tiff;创建导出的图层和组的 xml 布局,并从给定的图层创建纹理图集和动画集。它完全用 C# 编写。如果您希望其来源通过应用程序中关于对话框的支持链接通知我。
回答by Adam Mac
I got extraction from psd working. see my answer here
我从 psd 工作中提取。在这里看到我的答案
How to extract layers from a Photoshop file? C#
may help someone else.
可能会帮助别人。
回答by Adam
I've had great success with Aspose's Imaging component which can load and save PSD files without Photoshop: https://products.aspose.com/imaging/net
我使用 Aspose 的 Imaging 组件取得了巨大成功,该组件无需 Photoshop 即可加载和保存 PSD 文件:https: //products.aspose.com/imaging/net
回答by Usman Aziz
You can use GroupDocs.Viewer for .NETAPI to render your PSD files as images (JPG, PNG, BMP) in your application using a few lines of code.
您可以使用GroupDocs.Viewer for .NETAPI 在应用程序中使用几行代码将 PSD 文件呈现为图像(JPG、PNG、BMP)。
C#
C#
ViewerConfig config = new ViewerConfig();
config.StoragePath = "D:\storage\";
// Create handler
ViewerImageHandler imageHandler = new ViewerImageHandler(config);
// Guid implies that unique document name
string guid = "sample.psd";
// Get document pages as images
List<PageImage> pages = imageHandler.GetPages(guid);
foreach (PageImage page in pages)
{
// Access each image using page.Stream
}
For more details and sample code, please visit here. Disclosure: I work as a Developer Evangelist at GroupDocs.
有关更多详细信息和示例代码,请访问此处。 披露:我在 GroupDocs 担任开发人员布道师。