[]
Represents an uncompressed in-memory bitmap in 32-bit ARGB format (A is the most significant byte).
public class GcBitmap : IImage, IDisposable
Initializes an empty instance of the GcBitmap class.
public GcBitmap()
Initializes a new instance of the GcBitmap class.
public GcBitmap(Image image, Rectangle? imageRect = null, bool storeInTempFile = false)
image
ImageImage used as the source of image data.
imageRect
System.Drawing.Rectangle?Clipping rectangle of the image to be loaded.
storeInTempFile
boolIndicates whether pixel data should be dynamically mapped to a temporary file rather than kept fully in memory.
Initializes a new instance of the GcBitmap class.
public GcBitmap(byte[] bytes, int frameIndex = 0, Rectangle? imageRect = null, bool storeInTempFile = false)
bytes
byte[]The image data. JPEG, PNG, WEBP, GIF, BMP, TIFF, ICO, JPEG 2000 formats are supported.
frameIndex
intIndex 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
boolIndicates whether pixel data should be dynamically mapped to a temporary file rather than kept fully in memory.
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)
pixelWidth
intThe width of the image, in pixels.
pixelHeight
intThe height of the image, in pixels.
opaque
boolIndicates whether the alpha channel should be ignored.
dpiX
floatThe horizontal dpi of the image.
dpiY
floatThe vertical dpi of the image.
storeInTempFile
boolIndicates whether pixel data should be dynamically mapped to a temporary file rather than kept fully in memory.
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)
pixelData
System.IntPtrThe pixel data to be attached to a GcBitmap.
pixelWidth
intThe width of the image, in pixels.
pixelHeight
intThe height of the image, in pixels.
opaque
boolIndicates whether the alpha channel should be ignored.
premultiplied
boolIndicates if the color channels are premultiplied by the alpha channel.
dpiX
floatThe horizontal dpi of the image.
dpiY
floatThe vertical dpi of the image.
Initializes a new instance of the GcBitmap class.
public GcBitmap(Stream stream, int frameIndex = 0, Rectangle? imageRect = null, bool storeInTempFile = false)
stream
System.IO.StreamThe source stream. JPEG, PNG, WEBP, GIF, BMP, TIFF, ICO, JPEG 2000 formats are supported.
frameIndex
intIndex 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
boolIndicates whether pixel data should be dynamically mapped to a temporary file rather than kept fully in memory.
Initializes a new instance of the GcBitmap class.
public GcBitmap(string path, int frameIndex = 0, Rectangle? imageRect = null, bool storeInTempFile = false)
path
stringThe file path to the image. JPEG, PNG, WEBP, GIF, BMP, TIFF, ICO, JPEG 2000 formats are supported.
frameIndex
intIndex 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
boolIndicates whether pixel data should be dynamically mapped to a temporary file rather than kept fully in memory.
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)
pixelData
uint[]The pixel data to be attached to a GcBitmap.
pixelWidth
intThe width of the image, in pixels.
pixelHeight
intThe height of the image, in pixels.
opaque
boolIndicates whether the alpha channel should be ignored.
premultiplied
boolIndicates whether the color channels are premultiplied by the alpha channel.
dpiX
floatThe horizontal dpi of the image.
dpiY
floatThe vertical dpi of the image.
Gets the horizontal dpi of the bitmap.
public float DpiX { get; }
Gets the vertical dpi of the bitmap.
public float DpiY { get; }
Gets or sets an instance of ExifProfile with Exif metadata of the image.
public ExifProfile ExifProfile { get; set; }
Gets an instance of the GcBitmapGraphics class.
The Graphics becomes available after executing the CreateGraphics(Color?) method.
public GcBitmapGraphics Graphics { get; }
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; }
Gets the height of the image, in DIPs.
public float Height { get; }
Gets or sets the raw ICC profile data.
public byte[] IccProfileData { get; set; }
Gets a value indicating whether the GcBitmap has been disposed of.
public bool IsDisposed { get; }
Gets or sets a pixel color value at the specified coordinates.
public uint this[int x, int y] { get; set; }
x
intThe X coordinate.
y
intThe Y coordinate.
Gets or sets a value indicating whether the alpha channel of the image should be ignored.
public bool Opaque { get; set; }
Gets the pixel height of the image.
public int PixelHeight { get; }
Gets the pixel width of the image.
public int PixelWidth { get; }
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; }
Gets a pointer to the internal binary data.
public IntPtr RawData { get; }
Gets an instance of the BitmapRenderer class.
The renderer becomes available after executing the EnsureRendererCreated() method.
public BitmapRenderer Renderer { get; }
Gets the flip and rotate transformations that must be applied to the image.
public FlipRotateAction Rotation { get; }
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; }
Gets the width of the image, in DIPs.
public float Width { get; }
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)
blackPoint
System.Drawing.ColorwhitePoint
System.Drawing.ColoroutputBlack
System.Drawing.ColoroutputWhite
System.Drawing.Colormidtone
floatAdjusts 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)
blackPoint
uintThe input black point in 32-bit ARGB format (the Alpha channel is ignored).
whitePoint
uintThe input white point in 32-bit ARGB format (the Alpha channel is ignored).
outputBlack
uintThe output black point in 32-bit ARGB format (the Alpha channel is ignored).
outputWhite
uintThe output white point in 32-bit ARGB format (the Alpha channel is ignored).
midtone
floatThe value of gamma correction.
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)
srcBitmap
GcBitmapThe source bitmap.
xDst
intThe x-coordinate, in pixels, of the upper-left corner of the destination rectangle.
yDst
intThe 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
floatThe opacity [0, 1] of the source bitmap, to multiply to the source bitmap's alpha channel.
width
intThe width, in pixels, of the source and destination rectangles.
height
intThe height, in pixels, of the source and destination rectangles.
xSrc
intThe x-coordinate, in pixels, of the upper-left corner of the source rectangle.
ySrc
intThe y-coordinate, in pixels, of the upper-left corner of the source rectangle.
Multiplies RGBA values of the GcBitmap by a 5x4 matrix.
public void ApplyColorMatrix(ColorMatrix5x4 colorMatrix, Rectangle? clipRect = null)
colorMatrix
ColorMatrix5x4A 5x4 matrix for altering RGBA values of the GcBitmap.
clipRect
System.Drawing.Rectangle?The target rectangle of the GcBitmap.
Applies a graphic effect to an image or its portion in-place.
public void ApplyEffect(BaseInplaceEffect effect, Rectangle? targetRect = null)
effect
BaseInplaceEffectAn effect derived from BaseInplaceEffect to apply.
targetRect
System.Drawing.Rectangle?The target rectangle of the GcBitmap.
Applies a license key to an instance of GcBitmap.
public void ApplyLicenseKey(string key)
key
stringThe license key to set.
Applies a transparency mask to the current image or its portion.
public void ApplyTransparencyMask(BilevelBitmap transparencyMask, Rectangle? clipRect = null)
transparencyMask
BilevelBitmapA BilevelBitmap with the transparency mask.
clipRect
System.Drawing.Rectangle?The target rectangle of the GcBitmap.
Applies a transparency mask to the current image or its portion.
public void ApplyTransparencyMask(GrayscaleBitmap transparencyMask, Rectangle? clipRect = null)
transparencyMask
GrayscaleBitmapA GrayscaleBitmap with the transparency mask.
clipRect
System.Drawing.Rectangle?The target rectangle of the GcBitmap.
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)
keepRelativeIntensities
boolIndicates if the method should keep the relative intensities of the color channels unchanged.
lowClipPercent
floatThe percent of extremely low values to be clipped, not greater than 10.
highClipPercent
floatThe percent of extremely high values to be clipped, not greater than 10.
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)
srcBitmap
GcBitmapThe source bitmap.
xDst
intThe x-coordinate, in pixels, of the upper-left corner of the destination rectangle.
yDst
intThe 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
intThe width, in pixels, of the source and destination rectangles.
height
intThe height, in pixels, of the source and destination rectangles.
xSrc
intThe x-coordinate, in pixels, of the upper-left corner of the source rectangle.
ySrc
intThe y-coordinate, in pixels, of the upper-left corner of the source 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)
sourceRect
System.Drawing.Rectangle?The source rectangle of the GcBitmap.
Clears the GcBitmap with the specified color.
public void Clear(Color color, Rectangle? clipRect = null)
color
System.Drawing.ColorThe color to fill the image.
clipRect
System.Drawing.Rectangle?The target rectangle of the GcBitmap.
Clears the GcBitmap with the specified color.
public void Clear(uint color = 16777215, Rectangle? clipRect = null)
color
uintThe color to fill the image.
clipRect
System.Drawing.Rectangle?The target rectangle of the GcBitmap.
Creates a new GcBitmap with a fragment of the image.
public GcBitmap Clip(Rectangle rect, bool metadataOnly = false)
rect
System.Drawing.RectangleClipping rectangle of the source image to be extracted as a new GcBitmap.
metadataOnly
boolSpecifies 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.
Copies the image into an existing GcBitmap.
public void Clone(GcBitmap bmp, bool cloneExif = false, bool metadataOnly = false)
bmp
GcBitmapThe target GcBitmap object.
cloneExif
boolSpecifies whether the Exif metadata should be cloned (if exist), not just copied as a reference.
metadataOnly
boolSpecifies 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.
Creates a new GcBitmap with a copy of the image.
public GcBitmap Clone(bool cloneExif = false, bool metadataOnly = false)
cloneExif
boolSpecifies whether the Exif metadata should be cloned (if exist), not just copied as a reference.
metadataOnly
boolSpecifies 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.
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)
srcBitmap
GcBitmapThe source bitmap.
xDst
intThe x-coordinate, in pixels, of the upper-left corner of the destination rectangle.
yDst
intThe y-coordinate, in pixels, of the upper-left corner of the destination rectangle.
compositeMode
CompositeModeThe Porter Duff compositing method.
blendMode
BlendModeThe blending method used to mix the source and destination colors.
clipRect
System.Drawing.Rectangle?The affected rectangle of the destination GcBitmap.
width
intThe width, in pixels, of the source and destination rectangles.
height
intThe height, in pixels, of the source and destination rectangles.
xSrc
intThe x-coordinate, in pixels, of the upper-left corner of the source rectangle.
ySrc
intThe y-coordinate, in pixels, of the upper-left corner of the source rectangle.
Makes the alpha channel not premultiplied in the color channels and sets the Premultiplied property to False.
public void ConvertFromPremultipliedAlpha()
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)
clipRect
System.Drawing.RectangleThe target rectangle of the GcBitmap.
Converts a part of semitransparent image to opaque with specified background color.
public void ConvertToOpaque(Color backColor, Rectangle clipRect)
backColor
System.Drawing.ColorThe color to be used as background for transparent pixels.
clipRect
System.Drawing.RectangleThe target rectangle of the GcBitmap.
Converts an image with transparent or semitransparent pixels to fully opaque with specified background color.
public void ConvertToOpaque(Color backColor)
backColor
System.Drawing.ColorThe color to be used as background for transparent pixels.
Premultiplies the color channels by the alpha channel and sets the Premultiplied property to True.
public void ConvertToPremultipliedAlpha()
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)
clipRect
System.Drawing.RectangleThe target rectangle of the GcBitmap.
Creates an instance of the GcBitmapGraphics class.
public GcBitmapGraphics CreateGraphics(Color? backColor = null)
backColor
System.Drawing.Color?If not null, specifies the color to clear the image with.
A new instance of GcBitmapGraphics.
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)
pixelWidth
intThe width of the image, in pixels.
pixelHeight
intThe height of the image, in pixels.
opaque
boolIndicates if the alpha channel should be ignored.
dpiX
floatThe horizontal dpi of the image.
dpiY
floatThe vertical dpi of the image.
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)
pixelData
System.IntPtrThe pixel data to be attached to a GcBitmap.
pixelWidth
intThe width of the image, in pixels.
pixelHeight
intThe height of the image, in pixels.
opaque
boolIndicates if the alpha channel should be ignored.
premultiplied
boolIndicates if the color channels are premultiplied by the alpha channel.
dpiX
floatThe horizontal dpi of the image.
dpiY
floatThe vertical dpi of the image.
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)
pixelData
uint[]The pixel data to be attached to a GcBitmap.
pixelWidth
intThe width of the image, in pixels.
pixelHeight
intThe height of the image, in pixels.
opaque
boolIndicates if the alpha channel should be ignored.
premultiplied
boolIndicates if the color channels are premultiplied by the alpha channel.
dpiX
floatThe horizontal dpi of the image.
dpiY
floatThe vertical dpi of the image.
Releases the internal image and clears all metadata.
public void DiscardImage()
Clean up any resources being used.
public void Dispose()
Performs cleanup operations on managed and unmanaged resources.
protected virtual void Dispose(bool disposing)
disposing
boolCreates a BitmapRenderer that allows drawing on the GcBitmap if it has not been created yet.
public BitmapRenderer EnsureRendererCreated()
The newly created or existing renderer.
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)
destinationImage
GrayscaleBitmapThe target GrayscaleBitmap.
colorChannel
ColorChannelA channel of the source GcBitmap to be exported.
Creates a sorted array of unique colors for the current image.
public uint[] ExtractColors(Rectangle? clipRect = null)
clipRect
System.Drawing.Rectangle?The rectangle of the image to be processed.
An array of colors in ARGB format.
Performs cleanup operations on unmanaged resources.
protected ~GcBitmap()
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)
action
FlipRotateActionThe operation to be applied.
clipRect
System.Drawing.Rectangle?Clipping rectangle specifying the area of the source image to be processed.
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)
maxColors
intThe maximum number of opaque colors in the palette, from 8 and above.
skipTransparentPixels
boolIndicates if the pixels with value of alpha less than 128 shouldn't be taken into account.
The resulting array with palette colors.
Returns the coordinates of a rectangle with colors different from background.
public Rectangle GetContentRect(Color bgColor)
bgColor
System.Drawing.ColorThe background color.
A part of the source image excluding the margins with background color.
Returns the coordinates of a rectangle with colors different from background.
public Rectangle GetContentRect(uint bgColor)
bgColor
uintThe background color.
A part of the source image excluding the margins with background color.
Determines whether the image contains transparent or semitransparent pixels.
It always returns false for an opaque image.
public bool HasTransparentPixels(Rectangle? clipRect = null)
clipRect
System.Drawing.Rectangle?The source rectangle of the GcBitmap.
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)
sourceImage
GrayscaleBitmapA GrayscaleBitmap with source data.
colorChannel
ColorChannelA channel of the destination GcBitmap to be updated.
Determines whether the image contains only black and white pixels.
public bool IsBlackAndWhite()
true if all pixels in the image are either black or white, false if there are other colors.
Determines whether the image contains only opaque grayscale pixels.
public bool IsGrayscale()
true if all pixels in the image are grayscale, false if there are other colors.
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)
bytes
byte[]The image data.
frameIndex
intIndex 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.
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)
stream
System.IO.StreamThe source stream.
frameIndex
intIndex 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.
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)
path
stringThe file path to the image.
frameIndex
intIndex 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.
Merges sorted arrays of unique colors in 32-bit ARGB format (returned from ExtractColors(Rectangle?))
public static uint[] MergePalettes(int minimalAlpha, params uint[][] palettes)
minimalAlpha
intPalette 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.
A sorted array with unique colors presented in one palette at least.
Creates a new GcBitmap with a resized image fragment.
public GcBitmap Resize(int targetPixelWidth, int targetPixelHeight, InterpolationMode interpolationMode = InterpolationMode.Linear, Rectangle? clipRect = null)
targetPixelWidth
intThe width of the resized image, in pixels.
targetPixelHeight
intThe height of the resized image, in pixels.
interpolationMode
InterpolationModeThe interpolation mode to use when scaling.
clipRect
System.Drawing.Rectangle?Clipping rectangle specifying the area of the source image to be processed.
Saves the image into a Stream in BMP format.
public void SaveAsBmp(Stream stream, Rectangle? clipRect = null)
stream
System.IO.StreamThe output stream.
clipRect
System.Drawing.Rectangle?Clipping rectangle of the image to be saved.
Saves the image into a file in BMP format.
public void SaveAsBmp(string path, Rectangle? clipRect = null)
path
stringThe output file path.
clipRect
System.Drawing.Rectangle?Clipping rectangle of the image to be saved.
Saves the image into a Stream in GIF format.
public void SaveAsGif(Stream stream, Rectangle? clipRect = null)
stream
System.IO.StreamThe output stream.
clipRect
System.Drawing.Rectangle?Clipping rectangle of the image to be saved.
Saves the image into a file in GIF format.
public void SaveAsGif(string path, Rectangle? clipRect = null)
path
stringThe output file path.
clipRect
System.Drawing.Rectangle?Clipping rectangle of the image to be saved.
Saves the image into a Stream in ICO format.
public void SaveAsIco(Stream stream, Rectangle? clipRect = null, IcoFrameEncoding encoding = IcoFrameEncoding.Png)
stream
System.IO.StreamThe output stream.
clipRect
System.Drawing.Rectangle?Clipping rectangle of the image to be saved.
encoding
IcoFrameEncodingEncoding of the frame image.
Saves the image into a file in ICO format.
public void SaveAsIco(string path, Rectangle? clipRect = null, IcoFrameEncoding encoding = IcoFrameEncoding.Png)
path
stringThe output file path.
clipRect
System.Drawing.Rectangle?Clipping rectangle of the image to be saved.
encoding
IcoFrameEncodingEncoding of the frame image.
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)
stream
System.IO.StreamThe output stream.
clipRect
System.Drawing.Rectangle?Clipping rectangle of the image to be saved.
quality
intThe image quality from 0 (best compression) to 100 (best quality).
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)
path
stringThe output file path.
clipRect
System.Drawing.Rectangle?Clipping rectangle of the image to be saved.
quality
intThe image quality from 0 (best compression) to 100 (best quality).
Saves the image into a Stream in PNG format.
public void SaveAsPng(Stream stream, Rectangle? clipRect = null)
stream
System.IO.StreamThe output stream.
clipRect
System.Drawing.Rectangle?Clipping rectangle of the image to be saved.
Saves the image into a file in PNG format.
public void SaveAsPng(string path, Rectangle? clipRect = null)
path
stringThe output file path.
clipRect
System.Drawing.Rectangle?Clipping rectangle of the image to be saved.
Saves the image into a Stream in TIFF format.
public void SaveAsTiff(Stream stream, Rectangle? clipRect = null, TiffFrameSettings frameSettings = null)
stream
System.IO.StreamThe output stream.
clipRect
System.Drawing.Rectangle?Clipping rectangle of the image to be saved.
frameSettings
TiffFrameSettingsThe settings for encoding TIFF frame.
Saves the image into a file in TIFF format.
public void SaveAsTiff(string path, Rectangle? clipRect = null, TiffFrameSettings frameSettings = null)
path
stringThe output file path.
clipRect
System.Drawing.Rectangle?Clipping rectangle of the image to be saved.
frameSettings
TiffFrameSettingsThe settings for encoding TIFF frame.
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)
stream
System.IO.StreamThe output stream.
clipRect
System.Drawing.Rectangle?Clipping rectangle of the image to be saved.
lossless
boolEither lossless (true) or lossy (false) webp format.
quality
intThe compression quality. Between 0 and 100.
method
intThe encoding method to use. Its a quality/speed trade-off (0=fast, 6=slower-better).
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)
path
stringThe output file path.
clipRect
System.Drawing.Rectangle?Clipping rectangle of the image to be saved.
lossless
boolEither lossless (true) or lossy (false) webp format.
quality
intThe compression quality. Between 0 and 100.
method
intThe encoding method to use. Its a quality/speed trade-off (0=fast, 6=slower-better).
Updates the alpha channel of pixels to 255 (to make them opaque).
public void SetAlphaTo255(Rectangle? clipRect = null)
clipRect
System.Drawing.Rectangle?The target rectangle of the GcBitmap.
Changes the physical resolution of the image.
public void SetDpi(float dpiX, float dpiY)
dpiX
floatThe horizontal resolution.
dpiY
floatThe vertical resolution.
Changes the physical resolution of the image.
public void SetDpi(float dpi)
dpi
floatThe horizontal and vertical resolution.
Sets the license key.
public static void SetLicenseKey(string key)
key
stringThe license key to set.
Changes pixel format from 8 bits per channel to lower values with two-dimensional error diffusion.
public void ShrinkARGBFormat(int bitsPerChannel, DitheringMethod ditheringMethod)
bitsPerChannel
intThe target number of bits per channel (from 1 to 8).
ditheringMethod
DitheringMethodThe method of two-dimensional error diffusion dithering.
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)
bitsPerAlpha
intThe target number of bits per Alpha channel (from 1 to 8), ignored for opaque images.
bitsPerRed
intThe target number of bits per Red channel (from 1 to 8).
bitsPerGreen
intThe target number of bits per Green channel (from 1 to 8).
bitsPerBlue
intThe target number of bits per Blue channel (from 1 to 8).
ditheringMethod
DitheringMethodThe method of two-dimensional error diffusion dithering.
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)
colorChannel
ColorChannelThe color channel used as the source of the bi-level data.
lowerBitsFirst
boolIf 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
boolIf true, indicates that 0 represents white and 1 represents black in the resulting BilevelBitmap.
A new instance of BilevelBitmap.
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)
colorChannel
ColorChannelThe color channel used as the source of grayscale data.
whiteIsZero
boolIf true, indicates that 0 represents white and 255 represents black in the resulting GrayscaleBitmap.
A new instance of GrayscaleBitmap.
Creates an Indexed4bppBitmap from the current image.
public Indexed4bppBitmap ToIndexed4bppBitmap(DitheringMethod ditheringMethod, bool lowerBitsFirst = false)
ditheringMethod
DitheringMethodThe method of two-dimensional error diffusion dithering.
lowerBitsFirst
boolIf 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.
A new instance of Indexed4bppBitmap.
Creates an opaque Indexed4bppBitmap from the current image using the Octree quantizer algorithm.
public Indexed4bppBitmap ToIndexed4bppBitmap(int maxColors, bool appendTransparentColor = false, bool lowerBitsFirst = false)
maxColors
intThe maximum number of opaque colors in the palette, from 8 to 16.
appendTransparentColor
boolIndicates 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
boolIf 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.
A new instance of Indexed4bppBitmap.
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)
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
DitheringMethodThe method of two-dimensional error diffusion dithering.
appendTransparentColor
boolIndicates 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
boolIf 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.
A new instance of Indexed4bppBitmap.
Creates an Indexed8bppBitmap from the current image.
public Indexed8bppBitmap ToIndexed8bppBitmap(DitheringMethod ditheringMethod)
ditheringMethod
DitheringMethodThe method of two-dimensional error diffusion dithering.
A new instance of Indexed8bppBitmap.
Creates an opaque Indexed8bppBitmap from the current image using the Octree quantizer algorithm.
public Indexed8bppBitmap ToIndexed8bppBitmap(int maxColors, bool appendTransparentColor = false)
maxColors
intThe maximum number of opaque colors in the palette, from 8 to 256.
appendTransparentColor
boolIndicates 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.
A new instance of Indexed8bppBitmap.
Creates an opaque Indexed8bppBitmap from the current image using the specified palette.
public Indexed8bppBitmap ToIndexed8bppBitmap(uint[] palette, DitheringMethod ditheringMethod, bool appendTransparentColor = false)
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
DitheringMethodThe method of two-dimensional error diffusion dithering.
appendTransparentColor
boolIndicates 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.
A new instance of Indexed8bppBitmap.
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)
quality
intThe image quality from 0 (best compression) to 100 (best quality).
The stream containing JPEG data.