Reading PSD file format

主宰稳场 提交于 2019-11-26 19:09:49

问题


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?

Basically I want the user to right click and click "image" which would save a .jpg of the file for them.

edit: will be using c# Thanks


回答1:


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




回答2:


The ImageMagick libraries (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.

A simple sample (found at http://midimick.com/magicknet/magickDoc.html) using MagickNet would look like this:

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




回答3:


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:

http://frankblumenberg.de/doku/doku.php?id=paintnet:psdplugin#download




回答4:


This guy do it easier:

http://www.codeproject.com/KB/graphics/simplepsd.aspx

With a C# library and a sample project.

I've tried with PS2 files and works ok.




回答5:


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




回答6:


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.




回答7:


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.

Check out their website: http://www.faststone.org/download.htm




回答8:


ImageMagick.NET - http://imagemagick.codeplex.com/ - is the later version of the link 0xA3 gave, with some slightly different syntax. (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");
}



回答9:


I got extraction from psd working. see my answer here

How to extract layers from a Photoshop file? C#

may help someone else.




回答10:


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.

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.




回答11:


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



来源:https://stackoverflow.com/questions/414852/reading-psd-file-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!