How to Display PSD Files in Delphi Installing and Using the GraphicEx Library
If you want to display Adobe Photoshop PSD files in Delphi, the GraphicEx library provides a simple and effective solution.
This page explains how to install GraphicEx and how to display PSD images using the TImage component, complete with practical source code examples.
It also introduces useful features such as retrieving the number of layers and saving images in bitmap format.
Downloading "GraphicEx"
Download the ZIP file from:
https://github.com/mike-lischke/GraphicEx
Click "Code" → "Download ZIP" to obtain the file "GraphicEx-master.zip".
After downloading, extract the ZIP archive.
Preparing to Use "GraphicEx" in Delphi
Start Delphi.
Open the menu: [Tools] → [Options].
Go to [Delphi] → [Library], then click the […] button next to “Library Path”.
Enter the full path to the folder where you extracted “GraphicEx-master.zip”, then click “Add”.
Click [OK] to close the dialog, then click [Save] to apply the settings.
Creating a New Project
Open the menu: [File] → [New] → [Windows VCL Application – Delphi].
Drag and drop a TButton, TImage, and TOpenDialog onto the form.
Select [File] → [Save All] to save the unit and project files.
Writing the Source Code
Double‑click “Button1” and enter the following source code.
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
private
{ Private }
public
{ Public }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses GraphicEx;
procedure TForm1.Button1Click(Sender: TObject);
var psd: TPSDGraphic;
begin
OpenDialog1.Filter := 'Photoshop|*.psd';
if not OpenDialog1.Execute() then Exit;
psd := TPSDGraphic.Create();
try
psd.LoadFromFile(OpenDialog1.FileName);
Image1.Picture.Assign(psd);
Image1.Stretch := True;
Image1.Proportional := True;
// You can save the PSD as a bitmap file
// psd.SaveToFile('a.bmp');
// psd.Layers.Count returns the number of layers
// psd.Layers[index].Image gives access to each layer's bitmap
// Example
// for i := 0 to psd.Layers.Count - 1 do
// begin
// bmp := psd.Layers[i].Image; // layer's bitmap
// end;
finally
psd.Free;
end;
end;
end.
Fixing the Error That Appears When Running the Project
When you run the project using [Run] → [Run], an error occurs at the following location.
The part shown in red below is causing the error.
uses
Windows, Classes, SysUtils, Graphics,
zLibEx, ZLibExApi; // general inflate/deflate and LZ77 compression support
Modify it as follows:
uses
Windows, Classes, SysUtils, Graphics,
zLib;
Running the Application
Select [Run] → [Run] to start the application.
Click “Button1” and choose a Photoshop (.psd) file.
Test files are included in the folder extracted from "GraphicEx-master.zip".
Folder: "GraphicEx-master\TestSuite original\PSD"
The selected .psd file will be displayed in Image1.
