[]
        
(Showing Draft Content)

GrapeCity.Documents.Imaging.GcBitmap

Class GcBitmap

Namespace
GrapeCity.Documents.Imaging
Assembly
GcDocs.Imaging.dll

Represents an uncompressed in-memory bitmap in 32-bit ARGB format (A is the most significant byte).

public class GcBitmap : IImage, IDisposable
Inheritance
object
GcBitmap
Implements
System.IDisposable
Inherited Members
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()

Constructors

GcBitmap()

Initializes an empty instance of the GcBitmap class.

public GcBitmap()

GcBitmap(Image, Rectangle?, bool)

Initializes a new instance of the GcBitmap class.

public GcBitmap(Image image, Rectangle? imageRect = null, bool storeInTempFile = false)

Parameters

image Image

Image used as the source of image data.

imageRect System.Drawing.Rectangle?

Clipping rectangle of the image to be loaded.

storeInTempFile bool

Indicates whether pixel data should be dynamically mapped to a temporary file rather than kept fully in memory.

GcBitmap(byte[], int, Rectangle?, bool)

Initializes a new instance of the GcBitmap class.

public GcBitmap(byte[] bytes, int frameIndex = 0, Rectangle? imageRect = null, bool storeInTempFile = false)

Parameters

bytes byte[]

The image data. JPEG, PNG, WEBP, GIF, BMP, TIFF, ICO, JPEG 2000 formats are supported.

frameIndex int

Index of an image frame to read, pass 0 for image formats not supporting multiple frames.

imageRect System.Drawing.Rectangle?

Clipping rectangle of the image to be loaded.

storeInTempFile bool

Indicates whether pixel data should be dynamically mapped to a temporary file rather than kept fully in memory.

GcBitmap(int, int, bool, float, float, bool)

Initializes a new instance of the GcBitmap class and creates the image.

The image content is not initialized and can contain any random data.

If subsequent rendering is going to cover the whole surface of the bitmap, or if CreateGraphics(Color?) will be called on the bitmap with a non-null background color, clearing it (which is a lengthy operation for large bitmaps) is not needed. If some areas of the bitmap are going to be left untouched, they must be cleared to avoid the possibility of random artifacts showing.

public GcBitmap(int pixelWidth, int pixelHeight, bool opaque, float dpiX = 96, float dpiY = 96, bool storeInTempFile = false)

Parameters

pixelWidth int

The width of the image, in pixels.

pixelHeight int

The height of the image, in pixels.

opaque bool

Indicates whether the alpha channel should be ignored.

dpiX float

The horizontal dpi of the image.

dpiY float

The vertical dpi of the image.

storeInTempFile bool

Indicates whether pixel data should be dynamically mapped to a temporary file rather than kept fully in memory.

GcBitmap(IntPtr, int, int, bool, bool, float, float)

Initializes a new instance of the GcBitmap class and sets the existing pixel data to be read/modified in-place.

public GcBitmap(IntPtr pixelData, int pixelWidth, int pixelHeight, bool opaque, bool premultiplied = false, float dpiX = 96, float dpiY = 96)

Parameters

pixelData System.IntPtr

The pixel data to be attached to a GcBitmap.

pixelWidth int

The width of the image, in pixels.

pixelHeight int

The height of the image, in pixels.

opaque bool

Indicates whether the alpha channel should be ignored.

premultiplied bool

Indicates if the color channels are premultiplied by the alpha channel.

dpiX float

The horizontal dpi of the image.

dpiY float

The vertical dpi of the image.

GcBitmap(Stream, int, Rectangle?, bool)

Initializes a new instance of the GcBitmap class.

public GcBitmap(Stream stream, int frameIndex = 0, Rectangle? imageRect = null, bool storeInTempFile = false)

Parameters

stream System.IO.Stream

The source stream. JPEG, PNG, WEBP, GIF, BMP, TIFF, ICO, JPEG 2000 formats are supported.

frameIndex int

Index of an image frame to read, pass 0 for image formats not supporting multiple frames.

imageRect System.Drawing.Rectangle?

Clipping rectangle of the image to be loaded.

storeInTempFile bool

Indicates whether pixel data should be dynamically mapped to a temporary file rather than kept fully in memory.

GcBitmap(string, int, Rectangle?, bool)

Initializes a new instance of the GcBitmap class.

public GcBitmap(string path, int frameIndex = 0, Rectangle? imageRect = null, bool storeInTempFile = false)

Parameters

path string

The file path to the image. JPEG, PNG, WEBP, GIF, BMP, TIFF, ICO, JPEG 2000 formats are supported.

frameIndex int

Index of an image frame to read, pass 0 for image formats not supporting multiple frames.

imageRect System.Drawing.Rectangle?

Clipping rectangle of the image to be loaded.

storeInTempFile bool

Indicates whether pixel data should be dynamically mapped to a temporary file rather than kept fully in memory.

GcBitmap(uint[], int, int, bool, bool, float, float)

Initializes a new instance of the GcBitmap class and sets the existing pixel data to be read/modified in-place.

public GcBitmap(uint[] pixelData, int pixelWidth, int pixelHeight, bool opaque, bool premultiplied = false, float dpiX = 96, float dpiY = 96)

Parameters

pixelData uint[]

The pixel data to be attached to a GcBitmap.

pixelWidth int

The width of the image, in pixels.

pixelHeight int

The height of the image, in pixels.

opaque bool

Indicates whether the alpha channel should be ignored.

premultiplied bool

Indicates whether the color channels are premultiplied by the alpha channel.

dpiX float

The horizontal dpi of the image.

dpiY float

The vertical dpi of the image.

Properties

DpiX

Gets the horizontal dpi of the bitmap.

public float DpiX { get; }

Property Value

float

DpiY

Gets the vertical dpi of the bitmap.

public float DpiY { get; }

Property Value

float

ExifProfile

Gets or sets an instance of ExifProfile with Exif metadata of the image.

public ExifProfile ExifProfile { get; set; }

Property Value

ExifProfile

Graphics

Gets an instance of the GcBitmapGraphics class.

The Graphics becomes available after executing the CreateGraphics(Color?) method.

public GcBitmapGraphics Graphics { get; }

Property Value

GcBitmapGraphics

HasImage

Gets a value indicating whether the underlying image exists (has been loaded or created). If this property is false, call Load() or CreateImage() to load or create the underlying image. Calling any other method will throw an exception unless this property is true.

public bool HasImage { get; }

Property Value

bool
See Also

Height

Gets the height of the image, in DIPs.

public float Height { get; }

Property Value

float

IccProfileData

Gets or sets the raw ICC profile data.

public byte[] IccProfileData { get; set; }

Property Value

byte[]

IsDisposed

Gets a value indicating whether the GcBitmap has been disposed of.

public bool IsDisposed { get; }

Property Value

bool

this[int, int]

Gets or sets a pixel color value at the specified coordinates.

public uint this[int x, int y] { get; set; }

Parameters

x int

The X coordinate.

y int

The Y coordinate.

Property Value

uint

Opaque

Gets or sets a value indicating whether the alpha channel of the image should be ignored.

public bool Opaque { get; set; }

Property Value

bool
See Also

PixelHeight

Gets the pixel height of the image.

public int PixelHeight { get; }

Property Value

int

PixelWidth

Gets the pixel width of the image.

public int PixelWidth { get; }

Property Value

int

Premultiplied

Gets or sets a value indicating if the color channels for all pixels are premultiplied by the alpha channel.

Setting this property doesn't perform actual conversion.

public bool Premultiplied { get; set; }

Property Value

bool
See Also

RawData

Gets a pointer to the internal binary data.

public IntPtr RawData { get; }

Property Value

System.IntPtr

Renderer

Gets an instance of the BitmapRenderer class.

The renderer becomes available after executing the EnsureRendererCreated() method.

public BitmapRenderer Renderer { get; }

Property Value

BitmapRenderer

Rotation

Gets the flip and rotate transformations that must be applied to the image.

public FlipRotateAction Rotation { get; }

Property Value

FlipRotateAction

StoreInTempFile

Gets or sets a value indicating whether pixel data should be dynamically mapped to a temporary file rather than kept fully in memory.

Setting this property to true frees up memory but slows down operations on pixel data.

Do not activate this mode for small images (less than 100 x 100 pixels).

The default is false.

public bool StoreInTempFile { get; set; }

Property Value

bool

Width

Gets the width of the image, in DIPs.

public float Width { get; }

Property Value

float

Methods

AdjustLevels(Color, Color, Color, Color, float)

Adjusts the levels of an image histogram.

The method maps the input range of values (blackPoint..whitePoint) to the output range (outputBlack..outputWhite) using the specified gamma correction (midtone).

public void AdjustLevels(Color blackPoint, Color whitePoint, Color outputBlack, Color outputWhite, float midtone = 1)

Parameters

blackPoint System.Drawing.Color
whitePoint System.Drawing.Color
outputBlack System.Drawing.Color
outputWhite System.Drawing.Color
midtone float

AdjustLevels(uint, uint, uint, uint, float)

Adjusts the levels of an image histogram.

The method maps the input range of values (blackPoint..whitePoint) to the output range (outputBlack..outputWhite) using the specified gamma correction (midtone).

public void AdjustLevels(uint blackPoint, uint whitePoint, uint outputBlack, uint outputWhite, float midtone = 1)

Parameters

blackPoint uint

The input black point in 32-bit ARGB format (the Alpha channel is ignored).

whitePoint uint

The input white point in 32-bit ARGB format (the Alpha channel is ignored).

outputBlack uint

The output black point in 32-bit ARGB format (the Alpha channel is ignored).

outputWhite uint

The output white point in 32-bit ARGB format (the Alpha channel is ignored).

midtone float

The value of gamma correction.

AlphaBlend(GcBitmap, int, int, Rectangle?, float, int, int, int, int)

Draws the source bitmap with the specified opacity into the current bitmap.

public void AlphaBlend(GcBitmap srcBitmap, int xDst, int yDst, Rectangle? clipRect = null, float opacity = 1, int width = 2147483647, int height = 2147483647, int xSrc = 0, int ySrc = 0)

Parameters

srcBitmap GcBitmap

The source bitmap.

xDst int

The x-coordinate, in pixels, of the upper-left corner of the destination rectangle.

yDst int

The y-coordinate, in pixels, of the upper-left corner of the destination rectangle.

clipRect System.Drawing.Rectangle?

The affected rectangle of the destination GcBitmap.

opacity float

The opacity [0, 1] of the source bitmap, to multiply to the source bitmap's alpha channel.

width int

The width, in pixels, of the source and destination rectangles.

height int

The height, in pixels, of the source and destination rectangles.

xSrc int

The x-coordinate, in pixels, of the upper-left corner of the source rectangle.

ySrc int

The y-coordinate, in pixels, of the upper-left corner of the source rectangle.

ApplyColorMatrix(ColorMatrix5x4, Rectangle?)

Multiplies RGBA values of the GcBitmap by a 5x4 matrix.

public void ApplyColorMatrix(ColorMatrix5x4 colorMatrix, Rectangle? clipRect = null)

Parameters

colorMatrix ColorMatrix5x4

A 5x4 matrix for altering RGBA values of the GcBitmap.

clipRect System.Drawing.Rectangle?

The target rectangle of the GcBitmap.

ApplyEffect(BaseInplaceEffect, Rectangle?)

Applies a graphic effect to an image or its portion in-place.

public void ApplyEffect(BaseInplaceEffect effect, Rectangle? targetRect = null)

Parameters

effect BaseInplaceEffect

An effect derived from BaseInplaceEffect to apply.

targetRect System.Drawing.Rectangle?

The target rectangle of the GcBitmap.

ApplyLicenseKey(string)

Applies a license key to an instance of GcBitmap.

public void ApplyLicenseKey(string key)

Parameters

key string

The license key to set.

ApplyTransparencyMask(BilevelBitmap, Rectangle?)

Applies a transparency mask to the current image or its portion.

public void ApplyTransparencyMask(BilevelBitmap transparencyMask, Rectangle? clipRect = null)

Parameters

transparencyMask BilevelBitmap

A BilevelBitmap with the transparency mask.

clipRect System.Drawing.Rectangle?

The target rectangle of the GcBitmap.

ApplyTransparencyMask(GrayscaleBitmap, Rectangle?)

Applies a transparency mask to the current image or its portion.

public void ApplyTransparencyMask(GrayscaleBitmap transparencyMask, Rectangle? clipRect = null)

Parameters

transparencyMask GrayscaleBitmap

A GrayscaleBitmap with the transparency mask.

clipRect System.Drawing.Rectangle?

The target rectangle of the GcBitmap.

AutoLevel(bool, float, float)

Modifies R, G, B color intensities such that the maximum range of values (0..255) is fully covered.

public void AutoLevel(bool keepRelativeIntensities = true, float lowClipPercent = 0.2, float highClipPercent = 0.2)

Parameters

keepRelativeIntensities bool

Indicates if the method should keep the relative intensities of the color channels unchanged.

lowClipPercent float

The percent of extremely low values to be clipped, not greater than 10.

highClipPercent float

The percent of extremely high values to be clipped, not greater than 10.

BitBlt(GcBitmap, int, int, Rectangle?, int, int, int, int)

Performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source bitmap into the current bitmap.

public void BitBlt(GcBitmap srcBitmap, int xDst, int yDst, Rectangle? clipRect = null, int width = 2147483647, int height = 2147483647, int xSrc = 0, int ySrc = 0)

Parameters

srcBitmap GcBitmap

The source bitmap.

xDst int

The x-coordinate, in pixels, of the upper-left corner of the destination rectangle.

yDst int

The y-coordinate, in pixels, of the upper-left corner of the destination rectangle.

clipRect System.Drawing.Rectangle?

The affected rectangle of the destination GcBitmap.

width int

The width, in pixels, of the source and destination rectangles.

height int

The height, in pixels, of the source and destination rectangles.

xSrc int

The x-coordinate, in pixels, of the upper-left corner of the source rectangle.

ySrc int

The y-coordinate, in pixels, of the upper-left corner of the source rectangle.

CalculateOtsuThreshold(Rectangle?)

Calculates Otsu's threshold [0..255] for a grayscale image.

It is expected that the image is already converted to monochromatic gray.

public int CalculateOtsuThreshold(Rectangle? sourceRect = null)

Parameters

sourceRect System.Drawing.Rectangle?

The source rectangle of the GcBitmap.

Returns

int

Clear(Color, Rectangle?)

Clears the GcBitmap with the specified color.

public void Clear(Color color, Rectangle? clipRect = null)

Parameters

color System.Drawing.Color

The color to fill the image.

clipRect System.Drawing.Rectangle?

The target rectangle of the GcBitmap.

Clear(uint, Rectangle?)

Clears the GcBitmap with the specified color.

public void Clear(uint color = 16777215, Rectangle? clipRect = null)

Parameters

color uint

The color to fill the image.

clipRect System.Drawing.Rectangle?

The target rectangle of the GcBitmap.

Clip(Rectangle, bool)

Creates a new GcBitmap with a fragment of the image.

public GcBitmap Clip(Rectangle rect, bool metadataOnly = false)

Parameters

rect System.Drawing.Rectangle

Clipping rectangle of the source image to be extracted as a new GcBitmap.

metadataOnly bool

Specifies whether to copy the image metadata only, not actual pixel data. If false, the corresponding pixel data will be copied from the current GcBitmap. If true, the pixel data of the resulting GcBitmap remain uninitialized.

Returns

GcBitmap

Clone(GcBitmap, bool, bool)

Copies the image into an existing GcBitmap.

public void Clone(GcBitmap bmp, bool cloneExif = false, bool metadataOnly = false)

Parameters

bmp GcBitmap

The target GcBitmap object.

cloneExif bool

Specifies whether the Exif metadata should be cloned (if exist), not just copied as a reference.

metadataOnly bool

Specifies whether to copy the image metadata only, not actual pixel data. If false, the pixel data will be copied from the current GcBitmap. If true, the pixel data of the target GcBitmap remain uninitialized.

Clone(bool, bool)

Creates a new GcBitmap with a copy of the image.

public GcBitmap Clone(bool cloneExif = false, bool metadataOnly = false)

Parameters

cloneExif bool

Specifies whether the Exif metadata should be cloned (if exist), not just copied as a reference.

metadataOnly bool

Specifies whether to copy the image metadata only, not actual pixel data. If false, the pixel data will be copied from the current GcBitmap. If true, the pixel data of the resulting GcBitmap remain uninitialized.

Returns

GcBitmap

CompositeAndBlend(GcBitmap, int, int, CompositeMode, BlendMode, Rectangle?, int, int, int, int)

Applies the algorithms of Porter Duff compositing and blending to the current bitmap (used as backdrop, destination) and the source bitmap.

public void CompositeAndBlend(GcBitmap srcBitmap, int xDst, int yDst, CompositeMode compositeMode, BlendMode blendMode = BlendMode.Normal, Rectangle? clipRect = null, int width = 2147483647, int height = 2147483647, int xSrc = 0, int ySrc = 0)

Parameters

srcBitmap GcBitmap

The source bitmap.

xDst int

The x-coordinate, in pixels, of the upper-left corner of the destination rectangle.

yDst int

The y-coordinate, in pixels, of the upper-left corner of the destination rectangle.

compositeMode CompositeMode

The Porter Duff compositing method.

blendMode BlendMode

The blending method used to mix the source and destination colors.

clipRect System.Drawing.Rectangle?

The affected rectangle of the destination GcBitmap.

width int

The width, in pixels, of the source and destination rectangles.

height int

The height, in pixels, of the source and destination rectangles.

xSrc int

The x-coordinate, in pixels, of the upper-left corner of the source rectangle.

ySrc int

The y-coordinate, in pixels, of the upper-left corner of the source rectangle.

ConvertFromPremultipliedAlpha()

Makes the alpha channel not premultiplied in the color channels and sets the Premultiplied property to False.

public void ConvertFromPremultipliedAlpha()

ConvertFromPremultipliedAlpha(Rectangle)

Makes the alpha channel of the specified rectangle not premultiplied in the color channels.

The Premultiplied property is not affected by this overload.

public void ConvertFromPremultipliedAlpha(Rectangle clipRect)

Parameters

clipRect System.Drawing.Rectangle

The target rectangle of the GcBitmap.

ConvertToOpaque(Color, Rectangle)

Converts a part of semitransparent image to opaque with specified background color.

public void ConvertToOpaque(Color backColor, Rectangle clipRect)

Parameters

backColor System.Drawing.Color

The color to be used as background for transparent pixels.

clipRect System.Drawing.Rectangle

The target rectangle of the GcBitmap.

ConvertToOpaque(Color)

Converts an image with transparent or semitransparent pixels to fully opaque with specified background color.

public void ConvertToOpaque(Color backColor)

Parameters

backColor System.Drawing.Color

The color to be used as background for transparent pixels.

ConvertToPremultipliedAlpha()

Premultiplies the color channels by the alpha channel and sets the Premultiplied property to True.

public void ConvertToPremultipliedAlpha()

ConvertToPremultipliedAlpha(Rectangle)

Premultiplies the color channels of the specified rectangle by the alpha channel.

The Premultiplied property is not affected by this overload.

public void ConvertToPremultipliedAlpha(Rectangle clipRect)

Parameters

clipRect System.Drawing.Rectangle

The target rectangle of the GcBitmap.

CreateGraphics(Color?)

Creates an instance of the GcBitmapGraphics class.

public GcBitmapGraphics CreateGraphics(Color? backColor = null)

Parameters

backColor System.Drawing.Color?

If not null, specifies the color to clear the image with.

Returns

GcBitmapGraphics

A new instance of GcBitmapGraphics.

CreateImage(int, int, bool, float, float)

Creates the image of the given size and resolution.

The content is not initialized and can contain any random data.

If subsequent rendering is going to cover the whole surface of the bitmap, or if CreateGraphics(Color?) will be called on the bitmap with a non-null background color, clearing it (which is a lengthy operation for large bitmaps) is not needed. If some areas of the bitmap are going to be left untouched, they must be cleared to avoid the possibility of random artifacts showing.

public void CreateImage(int pixelWidth, int pixelHeight, bool opaque, float dpiX = 96, float dpiY = 96)

Parameters

pixelWidth int

The width of the image, in pixels.

pixelHeight int

The height of the image, in pixels.

opaque bool

Indicates if the alpha channel should be ignored.

dpiX float

The horizontal dpi of the image.

dpiY float

The vertical dpi of the image.

CreateImage(IntPtr, int, int, bool, bool, float, float)

Creates the image based on the existing pixel data to be read/modified in-place.

public void CreateImage(IntPtr pixelData, int pixelWidth, int pixelHeight, bool opaque, bool premultiplied = false, float dpiX = 96, float dpiY = 96)

Parameters

pixelData System.IntPtr

The pixel data to be attached to a GcBitmap.

pixelWidth int

The width of the image, in pixels.

pixelHeight int

The height of the image, in pixels.

opaque bool

Indicates if the alpha channel should be ignored.

premultiplied bool

Indicates if the color channels are premultiplied by the alpha channel.

dpiX float

The horizontal dpi of the image.

dpiY float

The vertical dpi of the image.

CreateImage(uint[], int, int, bool, bool, float, float)

Creates the image based on the existing pixel data to be read/modified in-place.

public void CreateImage(uint[] pixelData, int pixelWidth, int pixelHeight, bool opaque, bool premultiplied = false, float dpiX = 96, float dpiY = 96)

Parameters

pixelData uint[]

The pixel data to be attached to a GcBitmap.

pixelWidth int

The width of the image, in pixels.

pixelHeight int

The height of the image, in pixels.

opaque bool

Indicates if the alpha channel should be ignored.

premultiplied bool

Indicates if the color channels are premultiplied by the alpha channel.

dpiX float

The horizontal dpi of the image.

dpiY float

The vertical dpi of the image.

DiscardImage()

Releases the internal image and clears all metadata.

public void DiscardImage()

Dispose()

Clean up any resources being used.

public void Dispose()

Dispose(bool)

Performs cleanup operations on managed and unmanaged resources.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

EnsureRendererCreated()

Creates a BitmapRenderer that allows drawing on the GcBitmap if it has not been created yet.

public BitmapRenderer EnsureRendererCreated()

Returns

BitmapRenderer

The newly created or existing renderer.

ExportColorChannel(GrayscaleBitmap, ColorChannel)

Copies data from one color channel of the current GcBitmap to an existing GrayscaleBitmap of the same pixel size.

public void ExportColorChannel(GrayscaleBitmap destinationImage, ColorChannel colorChannel)

Parameters

destinationImage GrayscaleBitmap

The target GrayscaleBitmap.

colorChannel ColorChannel

A channel of the source GcBitmap to be exported.

ExtractColors(Rectangle?)

Creates a sorted array of unique colors for the current image.

public uint[] ExtractColors(Rectangle? clipRect = null)

Parameters

clipRect System.Drawing.Rectangle?

The rectangle of the image to be processed.

Returns

uint[]

An array of colors in ARGB format.

~GcBitmap()

Performs cleanup operations on unmanaged resources.

protected ~GcBitmap()

FlipRotate(FlipRotateAction, Rectangle?)

Produces a flipped (horizontal or vertical) and/or rotated (by 90 degree increments) bitmap.

The source bitmap remains unchanged.

public GcBitmap FlipRotate(FlipRotateAction action, Rectangle? clipRect = null)

Parameters

action FlipRotateAction

The operation to be applied.

clipRect System.Drawing.Rectangle?

Clipping rectangle specifying the area of the source image to be processed.

Returns

GcBitmap

A new GcBitmap with transformed image.

GenerateOctreePalette(int, bool)

Generates a palette for the image using the Octree quantizer algorithm.

The Alpha color channel is ignored.

public uint[] GenerateOctreePalette(int maxColors, bool skipTransparentPixels = false)

Parameters

maxColors int

The maximum number of opaque colors in the palette, from 8 and above.

skipTransparentPixels bool

Indicates if the pixels with value of alpha less than 128 shouldn't be taken into account.

Returns

uint[]

The resulting array with palette colors.

GetContentRect(Color)

Returns the coordinates of a rectangle with colors different from background.

public Rectangle GetContentRect(Color bgColor)

Parameters

bgColor System.Drawing.Color

The background color.

Returns

System.Drawing.Rectangle

A part of the source image excluding the margins with background color.

GetContentRect(uint)

Returns the coordinates of a rectangle with colors different from background.

public Rectangle GetContentRect(uint bgColor)

Parameters

bgColor uint

The background color.

Returns

System.Drawing.Rectangle

A part of the source image excluding the margins with background color.

HasTransparentPixels(Rectangle?)

Determines whether the image contains transparent or semitransparent pixels.

It always returns false for an opaque image.

public bool HasTransparentPixels(Rectangle? clipRect = null)

Parameters

clipRect System.Drawing.Rectangle?

The source rectangle of the GcBitmap.

Returns

bool

ImportColorChannel(GrayscaleBitmap, ColorChannel)

Copies data from a GrayscaleBitmap to one color channel of the current GcBitmap of the same pixel size.

public void ImportColorChannel(GrayscaleBitmap sourceImage, ColorChannel colorChannel)

Parameters

sourceImage GrayscaleBitmap

A GrayscaleBitmap with source data.

colorChannel ColorChannel

A channel of the destination GcBitmap to be updated.

IsBlackAndWhite()

Determines whether the image contains only black and white pixels.

public bool IsBlackAndWhite()

Returns

bool

true if all pixels in the image are either black or white, false if there are other colors.

IsGrayscale()

Determines whether the image contains only opaque grayscale pixels.

public bool IsGrayscale()

Returns

bool

true if all pixels in the image are grayscale, false if there are other colors.

Load(byte[], int, Rectangle?)

Loads the image from a byte array. JPEG, PNG, WEBP, GIF, BMP, TIFF, ICO, JPEG 2000 formats are supported.

public void Load(byte[] bytes, int frameIndex = 0, Rectangle? imageRect = null)

Parameters

bytes byte[]

The image data.

frameIndex int

Index of an image frame to read, pass 0 for image formats not supporting multiple frames.

imageRect System.Drawing.Rectangle?

Clipping rectangle of the image to be loaded.

Load(Stream, int, Rectangle?)

Loads the image from a stream. JPEG, PNG, WEBP, GIF, BMP, TIFF, ICO, JPEG 2000 formats are supported.

public void Load(Stream stream, int frameIndex = 0, Rectangle? imageRect = null)

Parameters

stream System.IO.Stream

The source stream.

frameIndex int

Index of an image frame to read, pass 0 for image formats not supporting multiple frames.

imageRect System.Drawing.Rectangle?

Clipping rectangle of the image to be loaded.

Load(string, int, Rectangle?)

Loads the image from a file. JPEG, PNG, WEBP, GIF, BMP, TIFF, ICO, JPEG 2000 formats are supported.

public void Load(string path, int frameIndex = 0, Rectangle? imageRect = null)

Parameters

path string

The file path to the image.

frameIndex int

Index of an image frame to read, pass 0 for image formats not supporting multiple frames.

imageRect System.Drawing.Rectangle?

Clipping rectangle of the image to be loaded.

MergePalettes(int, params uint[][])

Merges sorted arrays of unique colors in 32-bit ARGB format (returned from ExtractColors(Rectangle?))

public static uint[] MergePalettes(int minimalAlpha, params uint[][] palettes)

Parameters

minimalAlpha int

Palette entries with Alpha less than the specified value (between 0 and 255) are skipped.

palettes uint[][]

A set of palettes with sorted arrays of unique colors.

Returns

uint[]

A sorted array with unique colors presented in one palette at least.

Resize(int, int, InterpolationMode, Rectangle?)

Creates a new GcBitmap with a resized image fragment.

public GcBitmap Resize(int targetPixelWidth, int targetPixelHeight, InterpolationMode interpolationMode = InterpolationMode.Linear, Rectangle? clipRect = null)

Parameters

targetPixelWidth int

The width of the resized image, in pixels.

targetPixelHeight int

The height of the resized image, in pixels.

interpolationMode InterpolationMode

The interpolation mode to use when scaling.

clipRect System.Drawing.Rectangle?

Clipping rectangle specifying the area of the source image to be processed.

Returns

GcBitmap

A new GcBitmap with resized image.

SaveAsBmp(Stream, Rectangle?)

Saves the image into a Stream in BMP format.

public void SaveAsBmp(Stream stream, Rectangle? clipRect = null)

Parameters

stream System.IO.Stream

The output stream.

clipRect System.Drawing.Rectangle?

Clipping rectangle of the image to be saved.

SaveAsBmp(string, Rectangle?)

Saves the image into a file in BMP format.

public void SaveAsBmp(string path, Rectangle? clipRect = null)

Parameters

path string

The output file path.

clipRect System.Drawing.Rectangle?

Clipping rectangle of the image to be saved.

SaveAsGif(Stream, Rectangle?)

Saves the image into a Stream in GIF format.

public void SaveAsGif(Stream stream, Rectangle? clipRect = null)

Parameters

stream System.IO.Stream

The output stream.

clipRect System.Drawing.Rectangle?

Clipping rectangle of the image to be saved.

SaveAsGif(string, Rectangle?)

Saves the image into a file in GIF format.

public void SaveAsGif(string path, Rectangle? clipRect = null)

Parameters

path string

The output file path.

clipRect System.Drawing.Rectangle?

Clipping rectangle of the image to be saved.

SaveAsIco(Stream, Rectangle?, IcoFrameEncoding)

Saves the image into a Stream in ICO format.

public void SaveAsIco(Stream stream, Rectangle? clipRect = null, IcoFrameEncoding encoding = IcoFrameEncoding.Png)

Parameters

stream System.IO.Stream

The output stream.

clipRect System.Drawing.Rectangle?

Clipping rectangle of the image to be saved.

encoding IcoFrameEncoding

Encoding of the frame image.

SaveAsIco(string, Rectangle?, IcoFrameEncoding)

Saves the image into a file in ICO format.

public void SaveAsIco(string path, Rectangle? clipRect = null, IcoFrameEncoding encoding = IcoFrameEncoding.Png)

Parameters

path string

The output file path.

clipRect System.Drawing.Rectangle?

Clipping rectangle of the image to be saved.

encoding IcoFrameEncoding

Encoding of the frame image.

SaveAsJpeg(Stream, Rectangle?, int)

Saves the image into a Stream in JPEG format with specified quality (from 0 to 100).

public void SaveAsJpeg(Stream stream, Rectangle? clipRect = null, int quality = 95)

Parameters

stream System.IO.Stream

The output stream.

clipRect System.Drawing.Rectangle?

Clipping rectangle of the image to be saved.

quality int

The image quality from 0 (best compression) to 100 (best quality).

SaveAsJpeg(string, Rectangle?, int)

Saves the image to a file in JPEG format with specified quality (from 0 to 100).

public void SaveAsJpeg(string path, Rectangle? clipRect = null, int quality = 95)

Parameters

path string

The output file path.

clipRect System.Drawing.Rectangle?

Clipping rectangle of the image to be saved.

quality int

The image quality from 0 (best compression) to 100 (best quality).

SaveAsPng(Stream, Rectangle?)

Saves the image into a Stream in PNG format.

public void SaveAsPng(Stream stream, Rectangle? clipRect = null)

Parameters

stream System.IO.Stream

The output stream.

clipRect System.Drawing.Rectangle?

Clipping rectangle of the image to be saved.

SaveAsPng(string, Rectangle?)

Saves the image into a file in PNG format.

public void SaveAsPng(string path, Rectangle? clipRect = null)

Parameters

path string

The output file path.

clipRect System.Drawing.Rectangle?

Clipping rectangle of the image to be saved.

SaveAsTiff(Stream, Rectangle?, TiffFrameSettings)

Saves the image into a Stream in TIFF format.

public void SaveAsTiff(Stream stream, Rectangle? clipRect = null, TiffFrameSettings frameSettings = null)

Parameters

stream System.IO.Stream

The output stream.

clipRect System.Drawing.Rectangle?

Clipping rectangle of the image to be saved.

frameSettings TiffFrameSettings

The settings for encoding TIFF frame.

SaveAsTiff(string, Rectangle?, TiffFrameSettings)

Saves the image into a file in TIFF format.

public void SaveAsTiff(string path, Rectangle? clipRect = null, TiffFrameSettings frameSettings = null)

Parameters

path string

The output file path.

clipRect System.Drawing.Rectangle?

Clipping rectangle of the image to be saved.

frameSettings TiffFrameSettings

The settings for encoding TIFF frame.

SaveAsWebp(Stream, Rectangle?, bool, int, int)

Saves the image into a Stream in WEBP format.

public void SaveAsWebp(Stream stream, Rectangle? clipRect = null, bool lossless = false, int quality = 75, int method = 5)

Parameters

stream System.IO.Stream

The output stream.

clipRect System.Drawing.Rectangle?

Clipping rectangle of the image to be saved.

lossless bool

Either lossless (true) or lossy (false) webp format.

quality int

The compression quality. Between 0 and 100.

method int

The encoding method to use. Its a quality/speed trade-off (0=fast, 6=slower-better).

SaveAsWebp(string, Rectangle?, bool, int, int)

Saves the image to a file in WEBP format.

public void SaveAsWebp(string path, Rectangle? clipRect = null, bool lossless = false, int quality = 75, int method = 5)

Parameters

path string

The output file path.

clipRect System.Drawing.Rectangle?

Clipping rectangle of the image to be saved.

lossless bool

Either lossless (true) or lossy (false) webp format.

quality int

The compression quality. Between 0 and 100.

method int

The encoding method to use. Its a quality/speed trade-off (0=fast, 6=slower-better).

SetAlphaTo255(Rectangle?)

Updates the alpha channel of pixels to 255 (to make them opaque).

public void SetAlphaTo255(Rectangle? clipRect = null)

Parameters

clipRect System.Drawing.Rectangle?

The target rectangle of the GcBitmap.

SetDpi(float, float)

Changes the physical resolution of the image.

public void SetDpi(float dpiX, float dpiY)

Parameters

dpiX float

The horizontal resolution.

dpiY float

The vertical resolution.

SetDpi(float)

Changes the physical resolution of the image.

public void SetDpi(float dpi)

Parameters

dpi float

The horizontal and vertical resolution.

SetLicenseKey(string)

Sets the license key.

public static void SetLicenseKey(string key)

Parameters

key string

The license key to set.

ShrinkARGBFormat(int, DitheringMethod)

Changes pixel format from 8 bits per channel to lower values with two-dimensional error diffusion.

public void ShrinkARGBFormat(int bitsPerChannel, DitheringMethod ditheringMethod)

Parameters

bitsPerChannel int

The target number of bits per channel (from 1 to 8).

ditheringMethod DitheringMethod

The method of two-dimensional error diffusion dithering.

ShrinkARGBFormat(int, int, int, int, DitheringMethod)

Changes pixel format from 8 bits per channel to lower values with two-dimensional error diffusion.

public void ShrinkARGBFormat(int bitsPerAlpha, int bitsPerRed, int bitsPerGreen, int bitsPerBlue, DitheringMethod ditheringMethod)

Parameters

bitsPerAlpha int

The target number of bits per Alpha channel (from 1 to 8), ignored for opaque images.

bitsPerRed int

The target number of bits per Red channel (from 1 to 8).

bitsPerGreen int

The target number of bits per Green channel (from 1 to 8).

bitsPerBlue int

The target number of bits per Blue channel (from 1 to 8).

ditheringMethod DitheringMethod

The method of two-dimensional error diffusion dithering.

ToBilevelBitmap(ColorChannel, bool, bool)

Creates a BilevelBitmap from the current GcBitmap.

This method does not perform any transformations of the color palette. It is expected that the source GcBitmap has already been converted to bi-level palette using some thresholding or dithering effects. The ToBilevelBitmap(ColorChannel, bool, bool) method just copies data from a specified color channel to a new instance of the BilevelBitmap class.

public BilevelBitmap ToBilevelBitmap(ColorChannel colorChannel = ColorChannel.Blue, bool lowerBitsFirst = false, bool whiteIsZero = false)

Parameters

colorChannel ColorChannel

The color channel used as the source of the bi-level data.

lowerBitsFirst bool

If true, pixels are arranged within a byte such that pixels with lower column indices are stored in the lower-order bits of the byte.

whiteIsZero bool

If true, indicates that 0 represents white and 1 represents black in the resulting BilevelBitmap.

Returns

BilevelBitmap

A new instance of BilevelBitmap.

ToGrayscaleBitmap(ColorChannel, bool)

Creates a GrayscaleBitmap from the current GcBitmap.

This method does not perform any transformations of the color palette. It is expected that the source GcBitmap has already been converted to grayscale palette using a GrayscaleEffect or something like that. Alternatively, you can use this method to extract individual channels of a color image without any prior conversion, and treat the resulting GrayscaleBitmap simply as a representation of some image data with 8 bits per pixel. The ToGrayscaleBitmap(ColorChannel, bool) method just copies data from a specified color channel to a new instance of the GrayscaleBitmap class. If you need to copy some color channel to an existing instance of GrayscaleBitmap, use the ExportColorChannel(GrayscaleBitmap, ColorChannel) method instead.

public GrayscaleBitmap ToGrayscaleBitmap(ColorChannel colorChannel = ColorChannel.Blue, bool whiteIsZero = false)

Parameters

colorChannel ColorChannel

The color channel used as the source of grayscale data.

whiteIsZero bool

If true, indicates that 0 represents white and 255 represents black in the resulting GrayscaleBitmap.

Returns

GrayscaleBitmap

A new instance of GrayscaleBitmap.

ToIndexed4bppBitmap(DitheringMethod, bool)

Creates an Indexed4bppBitmap from the current image.

public Indexed4bppBitmap ToIndexed4bppBitmap(DitheringMethod ditheringMethod, bool lowerBitsFirst = false)

Parameters

ditheringMethod DitheringMethod

The method of two-dimensional error diffusion dithering.

lowerBitsFirst bool

If true, pixels are arranged within a byte such that pixels with lower column indices are stored in the lower-order bit tetrads of the byte.

Returns

Indexed4bppBitmap

A new instance of Indexed4bppBitmap.

ToIndexed4bppBitmap(int, bool, bool)

Creates an opaque Indexed4bppBitmap from the current image using the Octree quantizer algorithm.

public Indexed4bppBitmap ToIndexed4bppBitmap(int maxColors, bool appendTransparentColor = false, bool lowerBitsFirst = false)

Parameters

maxColors int

The maximum number of opaque colors in the palette, from 8 to 16.

appendTransparentColor bool

Indicates if a transparent color should be added to the palette, if the image is not opaque and the number of opaque colors is less than 16.

lowerBitsFirst bool

If true, pixels are arranged within a byte such that pixels with lower column indices are stored in the lower-order bit tetrads of the byte.

Returns

Indexed4bppBitmap

A new instance of Indexed4bppBitmap.

ToIndexed4bppBitmap(uint[], DitheringMethod, bool, bool)

Creates an opaque Indexed4bppBitmap from the current image using the specified palette.

public Indexed4bppBitmap ToIndexed4bppBitmap(uint[] palette, DitheringMethod ditheringMethod, bool appendTransparentColor = false, bool lowerBitsFirst = false)

Parameters

palette uint[]

The palette with opaque colors for the new image (colors are in 32-bit ARGB format). Elements with index 16 and above are ignored.

ditheringMethod DitheringMethod

The method of two-dimensional error diffusion dithering.

appendTransparentColor bool

Indicates if a transparent color should be added to the palette, if the image is not opaque and the number of opaque colors is less than 16.

lowerBitsFirst bool

If true, pixels are arranged within a byte such that pixels with lower column indices are stored in the lower-order bit tetrads of the byte.

Returns

Indexed4bppBitmap

A new instance of Indexed4bppBitmap.

ToIndexed8bppBitmap(DitheringMethod)

Creates an Indexed8bppBitmap from the current image.

public Indexed8bppBitmap ToIndexed8bppBitmap(DitheringMethod ditheringMethod)

Parameters

ditheringMethod DitheringMethod

The method of two-dimensional error diffusion dithering.

Returns

Indexed8bppBitmap

A new instance of Indexed8bppBitmap.

ToIndexed8bppBitmap(int, bool)

Creates an opaque Indexed8bppBitmap from the current image using the Octree quantizer algorithm.

public Indexed8bppBitmap ToIndexed8bppBitmap(int maxColors, bool appendTransparentColor = false)

Parameters

maxColors int

The maximum number of opaque colors in the palette, from 8 to 256.

appendTransparentColor bool

Indicates if a transparent color should be added to the palette, if the image is not opaque and the number of opaque colors is less than 256.

Returns

Indexed8bppBitmap

A new instance of Indexed8bppBitmap.

ToIndexed8bppBitmap(uint[], DitheringMethod, bool)

Creates an opaque Indexed8bppBitmap from the current image using the specified palette.

public Indexed8bppBitmap ToIndexed8bppBitmap(uint[] palette, DitheringMethod ditheringMethod, bool appendTransparentColor = false)

Parameters

palette uint[]

The palette with opaque colors for the new image (colors are in 32-bit ARGB format). Elements with index 256 and above are ignored.

ditheringMethod DitheringMethod

The method of two-dimensional error diffusion dithering.

appendTransparentColor bool

Indicates if a transparent color should be added to the palette, if the image is not opaque and the number of opaque colors is less than 256.

Returns

Indexed8bppBitmap

A new instance of Indexed8bppBitmap.

ToJpegStream(int)

Saves the image into a Stream in JPEG format with specified quality (from 0 to 100). The returned stream should be disposed after usage.

public MemoryStream ToJpegStream(int quality)

Parameters

quality int

The image quality from 0 (best compression) to 100 (best quality).

Returns

System.IO.MemoryStream

The stream containing JPEG data.