Class EncodedImage
An image kept as its file's bytes, such as a JPEG, for DrawImage(EncodedImage, RectF, SamplingOptions?, Paint?):
a backend that can store the bytes as they are, as a PDF page stores a JPEG as DCTDecode, gets them through
OnDrawEncodedImage without decoding and encoding again; every other backend draws the decoded pixels. The bytes are
probed when the image is made and decoded at most once, on first need. Immutable and thread-safe.
public sealed class EncodedImage
- Inheritance
-
EncodedImage
- Inherited Members
Examples
// A JPEG kept as its bytes: a PDF backend embeds them as they are; a raster canvas draws the decoded pixels.
EncodedImage jpeg = EncodedImage.Load("photo.jpg");
canvas.DrawImage(jpeg, new RectF(20, 20, 128, 96));
Properties
Data
Gets the file's bytes.
public ReadOnlyMemory<byte> Data { get; }
Property Value
Height
Gets the height of the decoded image in pixels.
public int Height { get; }
Property Value
Info
Gets what probing the bytes found: the format, the size, the pixel layout and the orientation.
public RasterInfo Info { get; }
Property Value
Width
Gets the width of the decoded image in pixels.
public int Width { get; }
Property Value
Methods
Decode()
Returns the decoded image, decoding it on the first call; later calls return the same raster, which must not be changed or disposed.
public Raster Decode()
Returns
- Raster
The decoded image.
Exceptions
- CorruptDataException
The image data is damaged.
Load(Stream, EgamiContext?)
Reads a stream to its end into an encoded image.
public static EncodedImage Load(Stream stream, EgamiContext? context = null)
Parameters
streamStreamThe stream.
contextEgamiContextThe context whose formats and limits apply, or null for the default.
Returns
- EncodedImage
The image.
Examples
// A JPEG kept as its bytes: a PDF backend embeds them as they are; a raster canvas draws the decoded pixels.
EncodedImage jpeg = EncodedImage.Load("photo.jpg");
canvas.DrawImage(jpeg, new RectF(20, 20, 128, 96));
Exceptions
- UnsupportedFormatException
The data is not an image Egami reads.
Load(ReadOnlyMemory<byte>, EgamiContext?)
Makes an encoded image from a file's bytes, which are kept as they are (not copied) and probed but not decoded; they must not change while the image is in use.
public static EncodedImage Load(ReadOnlyMemory<byte> data, EgamiContext? context = null)
Parameters
dataReadOnlyMemory<byte>The file's bytes, in any format Egami reads.
contextEgamiContextThe context whose formats and limits apply when probing and decoding, or null for the default.
Returns
- EncodedImage
The image.
Examples
// A JPEG kept as its bytes: a PDF backend embeds them as they are; a raster canvas draws the decoded pixels.
EncodedImage jpeg = EncodedImage.Load("photo.jpg");
canvas.DrawImage(jpeg, new RectF(20, 20, 128, 96));
Exceptions
- UnsupportedFormatException
The bytes are not an image Egami reads.
- CorruptDataException
The header is damaged.
Load(string, EgamiContext?)
Reads a file into an encoded image.
public static EncodedImage Load(string path, EgamiContext? context = null)
Parameters
pathstringThe file.
contextEgamiContextThe context whose formats and limits apply, or null for the default.
Returns
- EncodedImage
The image.
Examples
// A JPEG kept as its bytes: a PDF backend embeds them as they are; a raster canvas draws the decoded pixels.
EncodedImage jpeg = EncodedImage.Load("photo.jpg");
canvas.DrawImage(jpeg, new RectF(20, 20, 128, 96));
Exceptions
- UnsupportedFormatException
The file is not an image Egami reads.