简体   繁体   English

读取PSD文件格式

[英]Reading PSD file format

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.如果文件是 PSD,那么我希望程序提取图像。 Is this possible to do without having Photoshop installed?这可以在没有安装 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# 谢谢

The ImageMagick libraries (which provide bindings for C# ) also support the PSD format. ImageMagick库(为 C#提供绑定)也支持 PSD 格式。 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.它们可能比进入 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

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

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 文件并且工作正常。

I have written a PSD parser which extracts raster format layers from all versions of PSD and PSB.我编写了一个 PSD 解析器,它从所有版本的 PSD 和 PSB 中提取光栅格式层。 http://www.telegraphics.com.au/svn/psdparse/trunk http://www.telegraphics.com.au/svn/psdparse/trunk

You can use GroupDocs.Viewer for .NET API to render your PSD files as images (JPG, PNG, BMP) in your application using a few lines of code.您可以使用GroupDocs.Viewer for .NET API 在应用程序中使用几行代码将 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 担任开发人员布道师。

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

ImageMagick.NET - http://imagemagick.codeplex.com/ - is the later version of the link 0xA3 gave, with some slightly different syntax. ImageMagick.NET - http://imagemagick.codeplex.com/ - 是 0xA3 给出的链接的更高版本,语法略有不同。 (Note, this is untested): (注意,这是未经测试的):

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

Here is my own psd parser and exporter: http://papirosnik.info/psdsplit/ .这是我自己的 psd 解析器和导出器: 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;它允许正确解析带有 rgb 颜色 8、16 和 32 位通道的 psd,处理用户蒙版,将所选图层导出为 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.创建导出的图层和组的 xml 布局,并从给定的图层创建纹理图集和动画集。 It's entirely written in C#.它完全用 C# 编写。 If you want its sources inform me via support link on About dialog in the application.如果您希望其来源通过应用程序中关于对话框的支持链接通知我。

FastStone does this pretty efficiently. FastStone 非常有效地做到了这一点。 They do not have their libraries availaible, but I guess you can contact them and see if they can help.他们没有可用的图书馆,但我想您可以联系他们,看看他们是否可以提供帮助。

Check out their website: http://www.faststone.org/download.htm查看他们的网站: http : //www.faststone.org/download.htm

I got extraction from psd working.我从 psd 工作中提取。 see my answer here在这里看到我的答案

How to extract layers from a Photoshop file? 如何从 Photoshop 文件中提取图层? C# C#

may help someone else.可能会帮助别人。

我使用 Aspose 的 Imaging 组件取得了巨大成功,该组件无需 Photoshop 即可加载和保存 PSD 文件: https : //products.aspose.com/imaging/net

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM