Bitmap formats
Version 6.1.0
In this article
Overview
The Core build natively supports the following image formats:
- JPEG
- PNG
- Windows BMP
See details below.
The GDI+ and WPF builds rely on Windows libraries to read images and support more variations of JPEG, PNG, and BMP and also other formats like GIF and TIFF.
Image format | Core | GDI+ | WPF |
---|---|---|---|
JPEG | ✔️¹ | ✔️ | ✔️ |
PNG | ✔️² | ✔️ | ✔️ |
BMP | ✔️² | ✔️ | ✔️ |
GIF | - | ✔️ | ✔️ |
TIFF | - | ✔️ | ✔️ |
*¹ Supports JFIF and EXIF and some other variations of .JPG files, but some variations of .JPG files may not work.
*² Supports the most common formats like 1 BPP, 4 BPP, 8 BPP, 24 BPP, 32 BPP.
JPEG
The Core build natively supports JPEG images in the JFIF or EXIF format and some other formats. JPEG images can be RGB, grayscale or RGBW (inverted CMYK with four components per pixel).
The GDI+ and WPF builds rely on Windows libraries to read images and support more JPEG variations.
PNG
The Core build natively supports the following PNG variations:
- True Color with or without transparency
- Palette images with 256 colors
- Images with 256 gray scales
- Palette images with 16 colors (new with 6.1.0-preview-3)
- Palette images with 2 colors (new with 6.1.0-preview-3)
The GDI+ and WPF builds rely on Windows libraries to read images and support more PNG variations.
Windows BMP
The Core build natively supports the following Windows BMP variations:
- True Color with or without transparency
- Palette images with 16 or 256 colors
- Images with 256 gray scales
- Monochrome images
The GDI+ and WPF builds rely on Windows libraries to read images and support more Windows BMP variations and also OS/2 BMP files.
More formats
The Core build natively supports no other image formats beside JPEG, PNG, and BMP. Other images should be converted to Windows BMP or PNG for use with the Core build.
The GDI+ and WPF builds rely on Windows libraries to read images and support GIF, TIFF, and other formats supported by Windows.
Loading bitmap images
The XImage is used to load image files for use with PDFsharp.
Images can be loaded from a file.
var image = XImage.FromFile(jpegSamplePath);
Images can be loaded from a stream.
var image = XImage.FromStream(memoryStream);
Images can be loaded from resources attached to an application. In this case you access the attached resources through streams that can be used with XImage.FromStream
.
If you have an image file as a byte array, you can easily create a MemoryStream from that byte array and also use XImage.FromStream
to open it.