Table of Contents

Interface IMemoryImage

Namespace
NAPS2.Images
Assembly
NAPS2.Images.dll

A common interface to wrap around platform-specific implementations of an in-memory image (e.g. System.Drawing.Bitmap for Windows Forms).

public interface IMemoryImage : IImageStorage, IDisposable
Inherited Members
Extension Methods

Properties

Height

Gets the image's height in pixels.

int Height { get; }

Property Value

int

HorizontalResolution

Gets the image's horizontal resolution in pixels per inch.

float HorizontalResolution { get; }

Property Value

float

ImageContext

Gets the image context used to create this image.

ImageContext ImageContext { get; }

Property Value

ImageContext

LogicalPixelFormat

Gets the color content of the image. For example, an image might be stored in memory with PixelFormat = ARGB32, but if it's a grayscale image with no transparency, then LogicalPixelFormat = Gray8. By default this is not calculated and is set to ImagePixelFormat.Unsupported. Call IMemoryImage.UpdateLogicalPixelFormat() to ensure this is calculated.

ImagePixelFormat LogicalPixelFormat { get; set; }

Property Value

ImagePixelFormat

OriginalFileFormat

Gets the original image file's format (e.g. png/jpeg) if known.

ImageFileFormat OriginalFileFormat { get; set; }

Property Value

ImageFileFormat

PixelFormat

Gets the color representation that this image is capable of storing.

Callers shouldn't make assumptions about the actual in-memory binary format. If you need to know the actual representation, use the BitwiseImageData obtained from Lock().

See also LogicalPixelFormat for the actual color content of the image.

ImagePixelFormat PixelFormat { get; }

Property Value

ImagePixelFormat

VerticalResolution

Gets the image's vertical resolution in pixels per inch.

float VerticalResolution { get; }

Property Value

float

Width

Gets the image's width in pixels.

int Width { get; }

Property Value

int

Methods

Clone()

Creates a copy of the image so that one can be edited or disposed without affecting the other.

IMemoryImage Clone()

Returns

IMemoryImage

The copy.

Lock(LockMode, out BitwiseImageData)

Obtains access to the underlying binary data for the image.

ImageLockState Lock(LockMode lockMode, out BitwiseImageData imageData)

Parameters

lockMode LockMode

The access level (read/write) needed.

imageData BitwiseImageData

The raw binary image data.

Returns

ImageLockState

An object that, when disposed, releases the lock.

Save(Stream, ImageFileFormat, ImageSaveOptions?)

Saves the image to the given stream. The file format must be specified.

void Save(Stream stream, ImageFileFormat imageFormat, ImageSaveOptions? options = null)

Parameters

stream Stream

The stream to save the image to.

imageFormat ImageFileFormat

The file format to use.

options ImageSaveOptions

Options for saving, e.g. JPEG quality.

Save(string, ImageFileFormat, ImageSaveOptions?)

Saves the image to the given file path. If the file format is unspecified, it will be inferred from the file extension if possible.

void Save(string path, ImageFileFormat imageFormat = ImageFileFormat.Unknown, ImageSaveOptions? options = null)

Parameters

path string

The path to save the image file to.

imageFormat ImageFileFormat

The file format to use.

options ImageSaveOptions

Options for saving, e.g. JPEG quality.

SetResolution(float, float)

Sets the image's horizontal and vertical resolution in pixels per inch. This has no effect for invalid (zero or negative) values.

void SetResolution(float xDpi, float yDpi)

Parameters

xDpi float

The horizontal resolution.

yDpi float

The vertical resolution.