PdfImage class
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 PdfImageInheritance
Remarks
Section titled “Remarks”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.
Properties
Section titled “Properties”Format
Section titled “ Format”The source format.
public PdfImageFormat Format { get; }Property Value
Section titled “Property Value”HasTransparency
Section titled “ HasTransparency”True when the image carries transparency: an alpha channel or a transparent color.
public bool HasTransparency { get; }Property Value
Section titled “Property Value”Height
Section titled “ Height”Natural height in points as displayed, after EXIF orientation.
public double Height { get; }Property Value
Section titled “Property Value”HorizontalResolution
Section titled “ HorizontalResolution”Horizontal pixels per inch, as the file records it, else 96.
public double HorizontalResolution { get; }Property Value
Section titled “Property Value”PixelHeight
Section titled “ PixelHeight”Height of the stored image in pixels.
public int PixelHeight { get; }Property Value
Section titled “Property Value”PixelWidth
Section titled “ PixelWidth”Width of the stored image in pixels.
public int PixelWidth { get; }Property Value
Section titled “Property Value”VerticalResolution
Section titled “ VerticalResolution”Vertical pixels per inch, as the file records it, else 96.
public double VerticalResolution { get; }Property Value
Section titled “Property Value”Natural width in points as displayed, after EXIF orientation.
public double Width { get; }Property Value
Section titled “Property Value”Methods
Section titled “Methods”GetPageCount(string)
Section titled “ GetPageCount(string)”The number of pages in a TIFF file; 1 for the other formats.
public static int GetPageCount(string path)Parameters
Section titled “Parameters”path string
Returns
Section titled “Returns”Exceptions
Section titled “Exceptions”The data is not a supported image.
GetPageCount(byte[])
Section titled “ GetPageCount(byte[])”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)Parameters
Section titled “Parameters”data byte[]
Returns
Section titled “Returns”Exceptions
Section titled “Exceptions”The data is not a supported image.
Load(string)
Section titled “ Load(string)”Loads an image file: JPEG, PNG, GIF, BMP, TIFF (its first page) or WebP.
public static PdfImage Load(string path)Parameters
Section titled “Parameters”path string
Returns
Section titled “Returns”Exceptions
Section titled “Exceptions”The data is not a supported image, or is damaged.
Load(Stream)
Section titled “ Load(Stream)”Loads an image from a stream, read to its end.
public static PdfImage Load(Stream stream)Parameters
Section titled “Parameters”stream Stream
Returns
Section titled “Returns”Exceptions
Section titled “Exceptions”The data is not a supported image, or is damaged.
Load(byte[])
Section titled “ Load(byte[])”Loads an image from its bytes. The array is used directly; do not change it afterwards.
public static PdfImage Load(byte[] data)Parameters
Section titled “Parameters”data byte[]
Returns
Section titled “Returns”Exceptions
Section titled “Exceptions”The data is not a supported image, or is damaged.
Load(string, int)
Section titled “ Load(string, int)”Loads one page of a multi-page TIFF file. Other formats have only page 0.
public static PdfImage Load(string path, int page)Parameters
Section titled “Parameters”path string
The file.
page int
The page, from 0.
Returns
Section titled “Returns”Exceptions
Section titled “Exceptions”The data is not a supported image, or is damaged.
The image has no such page.
Load(byte[], int)
Section titled “ Load(byte[], int)”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)Parameters
Section titled “Parameters”data byte[]
The image file’s bytes, used directly; do not change them afterwards.
page int
The page, from 0.
Returns
Section titled “Returns”Exceptions
Section titled “Exceptions”The data is not a supported image, or is damaged.
The image has no such page.
Load(byte[], int, long)
Section titled “ Load(byte[], int, long)”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)Parameters
Section titled “Parameters”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).
Returns
Section titled “Returns”Exceptions
Section titled “Exceptions”The data is not a supported image, is damaged, or has more than maxPixels pixels.
The image has no such page, or maxPixels is out of range.