Class Image<TPixel>
Encapsulates an image, which consists of the pixel data for a graphics image and its attributes. For generic Image<TPixel>-s the pixel type is known at compile time.
Inherited Members
Namespace: SixLabors.ImageSharp
Assembly: SixLabors.ImageSharp.dll
Syntax
public sealed class Image<TPixel> : Image, IDisposable, IConfigurationProvider where TPixel : unmanaged, IPixel<TPixel>
Type Parameters
Name | Description |
---|---|
TPixel | The pixel format. |
Constructors
| Edit this page View SourceImage(Configuration, int, int)
Initializes a new instance of the Image<TPixel> class with the height and the width of the image.
Declaration
public Image(Configuration configuration, int width, int height)
Parameters
Type | Name | Description |
---|---|---|
Configuration | configuration | The configuration providing initialization code which allows extending the library. |
int | width | The width of the image in pixels. |
int | height | The height of the image in pixels. |
Image(Configuration, int, int, TPixel)
Initializes a new instance of the Image<TPixel> class with the height and the width of the image.
Declaration
public Image(Configuration configuration, int width, int height, TPixel backgroundColor)
Parameters
Type | Name | Description |
---|---|---|
Configuration | configuration | The configuration providing initialization code which allows extending the library. |
int | width | The width of the image in pixels. |
int | height | The height of the image in pixels. |
TPixel | backgroundColor | The color to initialize the pixels with. |
Image(int, int)
Initializes a new instance of the Image<TPixel> class with the height and the width of the image.
Declaration
public Image(int width, int height)
Parameters
Type | Name | Description |
---|---|---|
int | width | The width of the image in pixels. |
int | height | The height of the image in pixels. |
Image(int, int, TPixel)
Initializes a new instance of the Image<TPixel> class with the height and the width of the image.
Declaration
public Image(int width, int height, TPixel backgroundColor)
Parameters
Type | Name | Description |
---|---|---|
int | width | The width of the image in pixels. |
int | height | The height of the image in pixels. |
TPixel | backgroundColor | The color to initialize the pixels with. |
Properties
| Edit this page View SourceFrames
Gets the collection of image frames.
Declaration
public ImageFrameCollection<TPixel> Frames { get; }
Property Value
Type | Description |
---|---|
ImageFrameCollection<TPixel> |
this[int, int]
Gets or sets the pixel at the specified position.
Declaration
public TPixel this[int x, int y] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
int | x | The x-coordinate of the pixel. Must be greater than or equal to zero and less than the width of the image. |
int | y | The y-coordinate of the pixel. Must be greater than or equal to zero and less than the height of the image. |
Property Value
Type | Description |
---|---|
TPixel | The |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown when the provided (x,y) coordinates are outside the image boundary. |
NonGenericFrameCollection
Gets the ImageFrameCollection implementing the public Frames property.
Declaration
protected override ImageFrameCollection NonGenericFrameCollection { get; }
Property Value
Type | Description |
---|---|
ImageFrameCollection |
Overrides
Methods
| Edit this page View SourceClone()
Clones the current image
Declaration
public Image<TPixel> Clone()
Returns
Type | Description |
---|---|
Image<TPixel> | Returns a new image with all the same metadata as the original. |
Clone(Configuration)
Clones the current image with the given configuration.
Declaration
public Image<TPixel> Clone(Configuration configuration)
Parameters
Type | Name | Description |
---|---|---|
Configuration | configuration | The configuration providing initialization code which allows extending the library. |
Returns
Type | Description |
---|---|
Image<TPixel> | Returns a new Image<TPixel> with all the same pixel data as the original. |
CloneAs<TPixel2>(Configuration)
Returns a copy of the image in the given pixel format.
Declaration
public override Image<TPixel2> CloneAs<TPixel2>(Configuration configuration) where TPixel2 : unmanaged, IPixel<TPixel2>
Parameters
Type | Name | Description |
---|---|---|
Configuration | configuration | The configuration providing initialization code which allows extending the library. |
Returns
Type | Description |
---|---|
Image<TPixel2> | The Image<TPixel>. |
Type Parameters
Name | Description |
---|---|
TPixel2 | The pixel format. |
Overrides
| Edit this page View SourceCopyPixelDataTo(Span<byte>)
Copy image pixels to destination
.
Declaration
public void CopyPixelDataTo(Span<byte> destination)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | destination |
CopyPixelDataTo(Span<TPixel>)
Copy image pixels to destination
.
Declaration
public void CopyPixelDataTo(Span<TPixel> destination)
Parameters
Type | Name | Description |
---|---|---|
Span<TPixel> | destination | The Span<T> to copy image pixels to. |
DangerousTryGetSinglePixelMemory(out Memory<TPixel>)
Gets the representation of the pixels as a Memory<T> in the source image's pixel format stored in row major order, if the backing buffer is contiguous.
To ensure the memory is contiguous, PreferContiguousImageBuffers should be set to true, preferably on a non-global configuration instance (not Default). WARNING: Disposing or leaking the underlying image while still working with thememory
's Span<T>
might lead to memory corruption.
Declaration
public bool DangerousTryGetSinglePixelMemory(out Memory<TPixel> memory)
Parameters
Type | Name | Description |
---|---|---|
Memory<TPixel> | memory | The Memory<T> referencing the image buffer. |
Returns
Type | Description |
---|---|
bool | The bool indicating the success. |
Dispose(bool)
Disposes the object and frees resources for the Garbage Collector.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing | Whether to dispose of managed and unmanaged objects. |
Overrides
| Edit this page View SourceProcessPixelRows(PixelAccessorAction<TPixel>)
Execute processPixels
to process image pixels in a safe and efficient manner.
Declaration
public void ProcessPixelRows(PixelAccessorAction<TPixel> processPixels)
Parameters
Type | Name | Description |
---|---|---|
PixelAccessorAction<TPixel> | processPixels | The PixelAccessorAction<TPixel> defining the pixel operations. |
ProcessPixelRows<TPixel2>(Image<TPixel2>, PixelAccessorAction<TPixel, TPixel2>)
Execute processPixels
to process pixels of multiple images in a safe and efficient manner.
Declaration
public void ProcessPixelRows<TPixel2>(Image<TPixel2> image2, PixelAccessorAction<TPixel, TPixel2> processPixels) where TPixel2 : unmanaged, IPixel<TPixel2>
Parameters
Type | Name | Description |
---|---|---|
Image<TPixel2> | image2 | The second image. |
PixelAccessorAction<TPixel, TPixel2> | processPixels | The PixelAccessorAction<TPixel1, TPixel2> defining the pixel operations. |
Type Parameters
Name | Description |
---|---|
TPixel2 | The pixel type of the second image. |
ProcessPixelRows<TPixel2, TPixel3>(Image<TPixel2>, Image<TPixel3>, PixelAccessorAction<TPixel, TPixel2, TPixel3>)
Execute processPixels
to process pixels of multiple images in a safe and efficient manner.
Declaration
public void ProcessPixelRows<TPixel2, TPixel3>(Image<TPixel2> image2, Image<TPixel3> image3, PixelAccessorAction<TPixel, TPixel2, TPixel3> processPixels) where TPixel2 : unmanaged, IPixel<TPixel2> where TPixel3 : unmanaged, IPixel<TPixel3>
Parameters
Type | Name | Description |
---|---|---|
Image<TPixel2> | image2 | The second image. |
Image<TPixel3> | image3 | The third image. |
PixelAccessorAction<TPixel, TPixel2, TPixel3> | processPixels | The PixelAccessorAction<TPixel1, TPixel2, TPixel3> defining the pixel operations. |
Type Parameters
Name | Description |
---|---|
TPixel2 | The pixel type of the second image. |
TPixel3 | The pixel type of the third image. |
ToString()
Returns a string that represents the current object.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | A string that represents the current object. |