PsdSharp is a cross-platform .NET library for reading and rendering Photoshop PSD and PSB files, written entirely in managed C#.
$ dotnet add package PsdSharpPsdSharp is a fast, cross-platform .NET library for reading and rendering Photoshop PSD and PSB files in accordance with Adobe's Photoshop File Formats Specification, written entirely in managed C#.
PsdSharp is designed primarily for:
✏️ PsdSharp does not (yet) support writing or editing PSD files.
Duotone and multichannel images are rendered as grayscale due to an intentional lack of documentation by Adobe.
Simply add the PsdSharp NuGet package to your project:
dotnet add package PsdSharp
| Package | Description |
|---|
| PsdSharp.SkiaSharp | Convert ImageData to a SkiaSharp SKBitmap |
| PsdSharp.ImageSharp | Convert ImageData to an ImageSharp Image |
| PsdSharp.Avalonia | Avalonia control for viewing PSD files |
| PsdSharp.WPF | 🪟 Windows-only. Convert ImageData to a BitMapSource for WPF. |
| PsdSharp.Win32 | 🪟 Windows-only. Convert ImageData to a System.Drawing.Bitmap, i.e. for WinForms or the Win32 GDI+ API. |
To open a PSD file, simply use the PsdFile.Open method. This method accepts a stream.
using PsdSharp;
using var fileStream = File.Open("myFile.psd", FileMode.Open, FileAccess.Read, FileShare.Read);
var psdFile = PsdFile.Open(fileStream);
// Do something with the file...
var width = psdFile.Header.WidthInPixels;
var height = psdFile.Header.HeightInPixels;
//Get the raw composite image data as stored in the PSD file
var rawData = psdFile.ImageData.GetChannels().SelectMany(channel => channel.GetData()).ToArray();
//Or get a buffer with interleaved RGB data, which is more useful for rendering
var buffer = PixelDataConverter.GetInterleavedBuffer(psdFile.ImageData, ColorType.Rgba8888);
//You can also get the image data for a specific layer.
var layer = psdFile.Layers.First();
var buffer = PixelDataConverter.GetInterleavedBuffer(layer.ImageData, ColorType.Rgba8888);If you installed an extension package, you will find extension methods for converting the image data to a format suitable for the corresponding graphics library on the ImageData class. You can access the composite image data trough PsdFile.ImageData, and layer image data through Layer.ImageData.
The PsdSharp.Avalonia package adds a PsdView control. Sample usage is as follows:
//MainWindow.axaml
<avalonia:Window xmlns="https://github.com/avaloniaui"
xmlns:psdsharp="clr-namespace:PsdSharp.AvaloniaControls;assembly=PsdSharp.AvaloniaControls"
mc:Ignorable="d"
x:Class="PsdSharp.Avalonia.Sample.MainWindow"
Title="PsdSharp.Avalonia Sample"
Height="450"
Width="800">
<psdsharp:PsdView
x:Name="PsdView"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Height="1024"
Width="1024"
/>
</avalonia:Window>//MainWindow.axaml.cs
var psdStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("PsdSharp.Samples.Avalonia.Assets.test.psd");
PsdView.PsdFile = psdStream;The PsdFile.Open method accepts an optional second PsdLoadOptions parameter. This object can be used to configure how the library loads PSD files and whether image data should immediately be buffered into memory, cached to disk, or skipped entirely based on your needs.
The following parameters are available:
PsdFile.ImageData and Layer.ImageData properties will be null.No, this library currently only supports reading and rendering PSD and PSB files. There's currently no capability for creating new files or for modifying existing ones.
If your image is in color in Photoshop but grayscale when rendered through PsdSharp, you're most likely working with a Duotone or Multichannel image. These formats are intentionally undocumented by Adobe, and Adobe advises third-party vendors to render them as grayscale. To render them in color, convert the image to RGB, CMYK, Lab or Indexed color.
The recommended way is to use ImageSharp in tandem with PsdSharp. If you have the PsdSharp, PsdSharp.ImageSharp and ImageSharp NuGet packages installed, exporting becomes trivial:
var fileStream = File.Open("myFile.psd", FileMode.Open, FileAccess.Read, FileShare.Read);
var psdFile = PsdFile.Open(fileStream);
var image = psdFile.ImageData.ToImageSharpImage();
image.Save("myFile.png");No. This library reads PSD file metadata and converts Photoshop's image data into a more usable format. Compositing effects is out of scope.
Pull requests are welcome! If unsure about something, or if you want to make a major change, please open an issue first so we can discuss.
This project is licensed under the MIT License.