Class Image
Represents an image stored in consecutive memory with utilities for handling image data and memory buffers.
Implements
Inherited Members
Namespace: FFmpeg.Images
Assembly: FFmpeg.dll
Syntax
public sealed class Image : IDisposable
Properties
View SourceData
Gets the pointer to the raw image data.
Declaration
public nint Data { get; }
Property Value
| Type | Description |
|---|---|
| nint |
Height
Gets the height of the image in pixels.
Declaration
public int Height { get; }
Property Value
| Type | Description |
|---|---|
| int |
Info
Gets the information about the image, such as its dimensions, format, and alignment.
Declaration
public ImageInfo Info { get; }
Property Value
| Type | Description |
|---|---|
| ImageInfo |
PixelFormat
Gets the pixel format of the image.
Declaration
public PixelFormat PixelFormat { get; }
Property Value
| Type | Description |
|---|---|
| PixelFormat |
Width
Gets the width of the image in pixels.
Declaration
public int Width { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
View SourceConvertTo(ImageInfo)
Converts the current image to a different pixel format and returns the result as a new Image.
Declaration
public Image ConvertTo(ImageInfo dstFormat)
Parameters
| Type | Name | Description |
|---|---|---|
| ImageInfo | dstFormat | The desired destination format for the conversion. |
Returns
| Type | Description |
|---|---|
| Image | A new Image in the specified format. |
Exceptions
| Type | Condition |
|---|---|
| FFmpegException | Thrown if the conversion fails. |
Create(ImageInfo)
Declaration
public static Image Create(ImageInfo info)
Parameters
| Type | Name | Description |
|---|---|---|
| ImageInfo | info | The information used to describe the image. |
Returns
| Type | Description |
|---|---|
| Image | A new Image with an allocated buffer. |
Dispose()
Releases the resources used by the Image, including the underlying buffer.
Declaration
public void Dispose()
FromPixelCopy(ImageInfo, nint)
Creates a new Image by copying pixel data from the specified pointer.
Declaration
public static Image FromPixelCopy(ImageInfo info, nint data)
Parameters
| Type | Name | Description |
|---|---|---|
| ImageInfo | info | The image information such as dimensions and pixel format. |
| nint | data | A pointer to the source pixel data to be copied. |
Returns
| Type | Description |
|---|---|
| Image | A new Image with copied pixel data. |
FromPixelCopy(ImageInfo, ReadOnlySpan<byte>)
Creates a new Image by copying pixel data from the specified pointer.
Declaration
public static Image FromPixelCopy(ImageInfo info, ReadOnlySpan<byte> data)
Parameters
| Type | Name | Description |
|---|---|---|
| ImageInfo | info | The image information such as dimensions and pixel format. |
| ReadOnlySpan<byte> | data | A ReadOnlySpan to the source pixel data to be copied. |
Returns
| Type | Description |
|---|---|
| Image | A new Image with copied pixel data. |
FromPixels(ImageInfo, AVBuffer)
Declaration
public static Image FromPixels(ImageInfo info, AVBuffer data)
Parameters
| Type | Name | Description |
|---|---|---|
| ImageInfo | info | The image information such as dimensions and pixel format. |
| AVBuffer | data | The buffer that contains the pixel data. |
Returns
| Type | Description |
|---|---|
| Image | A new Image with the specified pixel data. |
FromPixels(ImageInfo, nint)
Creates a new Image using the provided pixel data pointer.
Declaration
public static Image FromPixels(ImageInfo info, nint data)
Parameters
| Type | Name | Description |
|---|---|---|
| ImageInfo | info | The image information such as dimensions and pixel format. |
| nint | data | A pointer to the pixel data. |
Returns
| Type | Description |
|---|---|
| Image | A new Image using the specified pixel data pointer. |
GetLineSize(Span<int>)
Retrieves the line sizes for each plane of the image and stores them in the provided span.
Declaration
public AVResult32 GetLineSize(Span<int> lineSizes)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<int> | lineSizes | The span to hold the line sizes for each plane of the image. |
Returns
| Type | Description |
|---|---|
| AVResult32 | An AVResult32 result indicating success or failure. If successful, the number of planes is returned. |
GetPlane(int)
Gets a span representing a single image plane.
Declaration
public Span<byte> GetPlane(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The zero-based index of the plane to retrieve. |
Returns
| Type | Description |
|---|---|
| Span<byte> | A Span<T> containing the bytes of the specified image plane. |
Remarks
The returned span references the underlying image buffer and does not allocate additional memory. Its length corresponds to the size of the plane as determined by the current PixelFormat, Width, and Height.
Multi-planar pixel formats (such as YUV formats) expose separate planes for components like luma and chroma, while packed pixel formats expose a single plane.
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |
GetPlanePointers(Span<nint>)
Retrieves the pointers to each plane of the image.
Declaration
public AVResult32 GetPlanePointers(Span<nint> planePtrs)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<nint> | planePtrs | The span to hold pointers to each plane of the image. |
Returns
| Type | Description |
|---|---|
| AVResult32 | An AVResult32 result indicating success or failure. If successful, the number of planes is returned. |
GetPlanes(Span<nint>, Span<int>)
Retrieves the pointers to each plane and their respective line sizes.
Declaration
public AVResult32 GetPlanes(Span<nint> planePtrs, Span<int> lineSizes)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<nint> | planePtrs | The span to hold pointers to each plane of the image. |
| Span<int> | lineSizes | The span to hold the line sizes for each plane of the image. |
Returns
| Type | Description |
|---|---|
| AVResult32 | An AVResult32 result indicating success or failure. If successful, the number of planes is returned. |