Skip to content

PdfImage class

View as Markdown

Namespace: PdfNetStack.Drawing
Assembly: PdfNetStack.dll
Package: PdfNetStack

A JPEG, PNG, GIF, BMP, TIFF or WebP image to draw with DrawImage. The image is written once per document however often it is drawn, and can be shared between documents and threads.

public sealed class PdfImage

Inheritance

object ← PdfImage

JPEGs are copied without recompression; EXIF orientation is honored, so photos stand upright. PNGs keep their compressed data when that is possible (no alpha channel, not interlaced) and otherwise are decoded once, their alpha becoming a soft mask. BMP, TIFF and WebP images are decoded when loaded, except a TIFF page stored as one strip of fax or JPEG data, which is copied. Embedded ICC profiles are kept when they describe the image’s color space. Multi-page TIFFs load one page at a time: see GetPageCount. Decoding is bounded: images over 2^28 pixels are refused.

The source format.

public PdfImageFormat Format { get; }

PdfImageFormat

True when the image carries transparency: an alpha channel or a transparent color.

public bool HasTransparency { get; }

bool

Natural height in points as displayed, after EXIF orientation.

public double Height { get; }

double

Horizontal pixels per inch, as the file records it, else 96.

public double HorizontalResolution { get; }

double

Height of the stored image in pixels.

public int PixelHeight { get; }

int

Width of the stored image in pixels.

public int PixelWidth { get; }

int

Vertical pixels per inch, as the file records it, else 96.

public double VerticalResolution { get; }

double

Natural width in points as displayed, after EXIF orientation.

public double Width { get; }

double

The number of pages in a TIFF file; 1 for the other formats.

public static int GetPageCount(string path)

path string

int

FormatException

The data is not a supported image.

The number of pages in a TIFF image; 1 for the other formats. Animated GIF and WebP images count as one page: their first frame is what loads.

public static int GetPageCount(byte[] data)

data byte[]

int

FormatException

The data is not a supported image.

Loads an image file: JPEG, PNG, GIF, BMP, TIFF (its first page) or WebP.

public static PdfImage Load(string path)

path string

PdfImage

FormatException

The data is not a supported image, or is damaged.

Loads an image from a stream, read to its end.

public static PdfImage Load(Stream stream)

stream Stream

PdfImage

FormatException

The data is not a supported image, or is damaged.

Loads an image from its bytes. The array is used directly; do not change it afterwards.

public static PdfImage Load(byte[] data)

data byte[]

PdfImage

FormatException

The data is not a supported image, or is damaged.

Loads one page of a multi-page TIFF file. Other formats have only page 0.

public static PdfImage Load(string path, int page)

path string

The file.

page int

The page, from 0.

PdfImage

FormatException

The data is not a supported image, or is damaged.

ArgumentOutOfRangeException

The image has no such page.

Loads one page of a multi-page TIFF from its bytes. Other formats have only page 0.

public static PdfImage Load(byte[] data, int page)

data byte[]

The image file’s bytes, used directly; do not change them afterwards.

page int

The page, from 0.

PdfImage

FormatException

The data is not a supported image, or is damaged.

ArgumentOutOfRangeException

The image has no such page.

Loads one page of an image file from its bytes, refusing an image with more pixels than maxPixels before decoding it. Use it to bound the memory an untrusted image can take: a decoded image holds up to four bytes per pixel.

public static PdfImage Load(byte[] data, int page, long maxPixels)

data byte[]

The image file’s bytes, used directly; do not change them afterwards.

page int

The page, from 0. Only TIFF files have more than page 0.

maxPixels long

Most pixels the image may have, from 1 to 2^28 (the default of the other overloads).

PdfImage

FormatException

The data is not a supported image, is damaged, or has more than maxPixels pixels.

ArgumentOutOfRangeException

The image has no such page, or maxPixels is out of range.