Table of Contents

Class RasterImage

Namespace
Rustaveli.Pdf
Assembly
Rustaveli.Pdf.dll

A JPEG or PNG image, to place with Image(IFrame, IImage, ImageFitting). Loading validates it without decoding it; a JPEG, and most PNGs, are embedded exactly as they were encoded.

public sealed class RasterImage : IImage
Inheritance
RasterImage
Implements
Inherited Members

Remarks

Loading reads headers and chunk structure only, so the layout can measure an image without paying for its pixels. Rustaveli.Pdf.RasterImage.Encode() does the work — trivial for a JPEG or a PNG that passes straight through, a full decode otherwise — once, on first use, and caches the result; it is safe to call from several threads.

An image placed many times should be embedded once. Rustaveli.Pdf.RasterImage.ContentHash identifies candidates cheaply, and HasSameContent(RasterImage) confirms them, so a writer can key its image objects on content rather than on which RasterImage instance a caller happened to load.

Properties

MaximumResolution

The most pixels per inch the image is embedded at where it is shown, or null to keep all its pixels unless the export asks otherwise.

public float? MaximumResolution { get; }

Property Value

float?

PixelHeight

The height in pixels, the right way up.

public int PixelHeight { get; }

Property Value

int

PixelWidth

The width in pixels, the right way up: an EXIF orientation that turns the image is applied.

public int PixelWidth { get; }

Property Value

int

Quality

The quality, from 1 to 100, the image is compressed at when it is embedded, or null to keep its own encoding unless the export asks otherwise.

public int? Quality { get; }

Property Value

int?

Methods

FromBytes(byte[])

Loads an image from data. The array is copied, so the caller may reuse it afterwards.

public static RasterImage FromBytes(byte[] data)

Parameters

data byte[]

Returns

RasterImage

Exceptions

ArgumentException

The data is not a well-formed JPEG or PNG, or uses a feature — such as a GIF or a lossless JPEG — that cannot be embedded. The inner exception says which.

FromFile(string)

Loads an image from the file at path.

public static RasterImage FromFile(string path)

Parameters

path string

Returns

RasterImage

Exceptions

ArgumentException

The file is not a JPEG or PNG that can be embedded.

FromStream(Stream)

Loads an image from the rest of stream, which need not be seekable. The stream is read to its end but not disposed.

public static RasterImage FromStream(Stream stream)

Parameters

stream Stream

Returns

RasterImage

Exceptions

ArgumentException

The stream does not hold a JPEG or PNG that can be embedded.

WithMaximumResolution(float)

The image, embedded at no more than pixelsPerInch where it is shown: an image placed smaller than its pixels need is scaled down. Needs an image processor at export.

public RasterImage WithMaximumResolution(float pixelsPerInch)

Parameters

pixelsPerInch float

Returns

RasterImage

WithQuality(int)

The image, to be compressed at quality from 1, smallest, to 100, finest, when embedded — as JPEG, or losslessly where it has transparency. Needs an image processor at export.

public RasterImage WithQuality(int quality)

Parameters

quality int

Returns

RasterImage