Gorgon
Show / Hide Table of Contents

Class GdiPlusExtensions

Extension methods to use GDI+ System.Drawing bitmaps with IGorgonImage

Inheritance
object
GdiPlusExtensions
Inherited Members
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: Gorgon.Graphics.Imaging.GdiPlus
Assembly: Gorgon.Graphics.Imaging.dll
Syntax
public static class GdiPlusExtensions

Methods

| Edit this page View Source

CopyTo(IGorgonImageBuffer, Bitmap)

Function to copy the contents of an individual IGorgonImageBuffer to a GDI+ bitmap object.

Declaration
public static void CopyTo(this IGorgonImageBuffer buffer, Bitmap bitmap)
Parameters
Type Name Description
IGorgonImageBuffer buffer

The buffer to convert.

Bitmap bitmap

The bitmap that will receive the image data.

Remarks

This method will take a IGorgonImageBuffer and copy its data into a new 2D Bitmap. The buffer and the bitmap must have an identical width and height. Otherwise, an exception will be thrown.

Some format conversion is performed on the buffer when it is imported. The format conversion will always convert to a pixel format of Format32bppArgb or Format24bppRgb. The following formats are supported for 32 bit conversion:

  • R8G8B8A8_UNorm
  • R8G8B8A8_UNorm_SRgb
  • R8G8B8A8_SInt
  • R8G8B8A8_SNorm
  • R8G8B8A8_UInt
  • R8G8B8A8_Typeless
  • B8G8R8A8_UNorm
  • B8G8R8A8_UNorm_SRgb
  • B8G8R8A8_Typeless
  • B8G8R8X8_UNorm
  • B8G8R8X8_UNorm_SRgb
  • B8G8R8X8_Typeless

If the source buffer does not support any of the formats on the lists, then an exception will be thrown.

Exceptions
Type Condition
ArgumentNullException

Thrown when the buffer, or the bitmap parameter is null.

ArgumentException

Thrown if the buffer and the bitmap do not have the same width and height.

GorgonException

Thrown if the buffer is not a 32 bit R8G8B8A8 format, or B8G8R8* format.

-or-

Thrown when the bitmap is not in a 32 bit ARGB format.

| Edit this page View Source

CopyTo(Bitmap, IGorgonImageBuffer)

Function to copy the contents of a GDI+ bitmap object to an individual IGorgonImageBuffer.

Declaration
public static void CopyTo(this Bitmap bitmap, IGorgonImageBuffer buffer)
Parameters
Type Name Description
Bitmap bitmap

The bitmap to convert.

IGorgonImageBuffer buffer

The buffer to that will receive the image data.

Remarks

This method will take a IGorgonImageBuffer and copy its data into a new 2D Bitmap. The buffer and the bitmap must have an identical width and height. Otherwise, an exception will be thrown.

Some format conversion is performed on the buffer when it is imported. The format conversion will always convert to a pixel format of Format32bppArgb or Format24bppRgb. The following formats are supported for 32 bit conversion:

  • R8G8B8A8_UNorm
  • R8G8B8A8_UNorm_SRgb
  • R8G8B8A8_SInt
  • R8G8B8A8_SNorm
  • R8G8B8A8_UInt
  • R8G8B8A8_Typeless
  • B8G8R8A8_UNorm
  • B8G8R8A8_UNorm_SRgb
  • B8G8R8A8_Typeless
  • B8G8R8X8_UNorm
  • B8G8R8X8_UNorm_SRgb
  • B8G8R8X8_Typeless

If the source buffer does not support any of the formats on the lists, then an exception will be thrown.

Exceptions
Type Condition
ArgumentNullException

Thrown when the bitmap, or the buffer parameter is null.

ArgumentException

Thrown if the bitmap and the buffer do not have the same width and height.

GorgonException

Thrown if the buffer is not a 32 bit R8G8B8A8 format, or B8G8R8* format.

-or-

Thrown when the bitmap is not in a 32 bit ARGB format.

| Edit this page View Source

ToBitmap(IGorgonImageBuffer)

Function to convert an individual IGorgonImageBuffer to a GDI+ bitmap object.

Declaration
public static Bitmap ToBitmap(this IGorgonImageBuffer buffer)
Parameters
Type Name Description
IGorgonImageBuffer buffer

The buffer to convert.

Returns
Type Description
Bitmap

A new GDI+ bitmap object.

Remarks

This method will take a IGorgonImageBuffer and copy its data into a new 2D Bitmap.

Some format conversion is performed on the buffer when it is imported. The format conversion will always convert to a pixel format of Format32bppArgb or Format24bppRgb. The following formats are supported for 32 bit conversion:

  • R8G8B8A8_UNorm
  • R8G8B8A8_UNorm_SRgb
  • R8G8B8A8_SInt
  • R8G8B8A8_SNorm
  • R8G8B8A8_UInt
  • R8G8B8A8_Typeless
  • B8G8R8A8_UNorm
  • B8G8R8A8_UNorm_SRgb
  • B8G8R8A8_Typeless
The following formats are supported for 24 bit conversion:
  • B8G8R8X8_UNorm
  • B8G8R8X8_UNorm_SRgb
  • B8G8R8X8_Typeless

If the source buffer does not support any of the formats on the lists, then an exception will be thrown.

Exceptions
Type Condition
ArgumentNullException

Thrown when the buffer parameter is null.

GorgonException

Thrown if the buffer is not a 32 bit R8G8B8A8 format, or B8G8R8* format.

| Edit this page View Source

ToGorgonImage(Bitmap)

Function to convert a Bitmap into a IGorgonImage.

Declaration
public static IGorgonImage ToGorgonImage(this Bitmap bitmap)
Parameters
Type Name Description
Bitmap bitmap

The Bitmap to convert.

Returns
Type Description
IGorgonImage

A new IGorgonImage containing the data from the Bitmap.

Remarks

This method will take a 2D Bitmap and copy its data into a new 2D IGorgonImage. The resulting IGorgonImage will only contain 1 array level, and no mip map levels.

Some format conversion is performed on the bitmap when it is imported. The format conversion will always convert to the image format of R8G8B8A8_UNorm. Only the following GDI+ pixel formats are supported for conversion:

  • Format32bppArgb
  • Format32bppPArgb
  • Format32bppRgb
  • Format24bppRgb
If the source bitmap does not support any of the formats on the list, then an exception will be thrown.
Exceptions
Type Condition
ArgumentNullException

Thrown when the bitmap parameter is null.

GorgonException

Thrown if the bitmap is not Format32bppArgb.

  • Edit this page
  • View Source
In this article
Back to top Copyright 2023 - Licensed under the MIT license by Michael Winsor (Tape_Worm).
Send comments on this topic to the author