[]
Represents a grayscale image or transparency mask with 8 bits per pixel.
public class GrayscaleBitmap : IImage, IDisposable
Initializes a new instance of the GrayscaleBitmap class and sets the existing pixel data to be read/modified in-place.
public GrayscaleBitmap(byte[] pixelData, int pixelWidth, int pixelHeight, bool transparencyMask = false, bool whiteIsZero = false, float dpiX = 96, float dpiY = 96)
pixelData byte[]The pixel data to be attached to a GrayscaleBitmap.
pixelWidth intThe width of the image, in pixels.
pixelHeight intThe height of the image, in pixels.
transparencyMask boolIf true, the image is used to define an irregularly shaped region of another image.
whiteIsZero boolIf true, specifies that 0 is imaged as white and 255 is imaged as black.
dpiX floatThe horizontal dpi of the image.
dpiY floatThe vertical dpi of the image.
Initializes a new instance of the GrayscaleBitmap class.
public GrayscaleBitmap(int pixelWidth, int pixelHeight, bool transparencyMask = false, bool whiteIsZero = false, float dpiX = 96, float dpiY = 96)
pixelWidth intThe width of the image, in pixels.
pixelHeight intThe height of the image, in pixels.
transparencyMask boolIf true, the image is used to define an irregularly shaped region of another image.
whiteIsZero boolIf true, specifies that 0 is imaged as white and 255 is imaged as black.
dpiX floatThe horizontal dpi of the image.
dpiY floatThe vertical dpi of the image.
Initializes a new instance of the GrayscaleBitmap class and sets the existing pixel data to be read/modified in-place.
public GrayscaleBitmap(IntPtr pixelData, int pixelWidth, int pixelHeight, bool transparencyMask = false, bool whiteIsZero = false, float dpiX = 96, float dpiY = 96)
pixelData System.IntPtrThe pixel data to be attached to a GrayscaleBitmap.
pixelWidth intThe width of the image, in pixels.
pixelHeight intThe height of the image, in pixels.
transparencyMask boolIf true, the image is used to define an irregularly shaped region of another image.
whiteIsZero boolIf true, specifies that 0 is imaged as white and 255 is imaged as black.
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 or sets the raw ICC profile data.
public byte[] IccProfileData { get; set; }
Gets a value indicating whether the GrayscaleBitmap has been disposed of.
public bool IsDisposed { get; }
Gets or sets a pixel value (from 0 to 255) at the specified coordinates.
public int this[int x, int y] { get; set; }
x intThe X coordinate.
y intThe Y coordinate.
Gets the pixel height of the image.
public int PixelHeight { get; }
Gets the pixel width of the image.
public int PixelWidth { get; }
Gets a pointer to the internal binary data.
public IntPtr RawData { 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 the image is used to define an irregularly shaped region of another image.
public bool TransparencyMask { get; set; }
Gets or sets a value specifying whether 0 represents white and 255 represents black (if true) or vice versa (if false).
public bool WhiteIsZero { get; set; }
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(int blackPoint, int whitePoint, int outputBlack, int outputWhite, float midtone = 1)
blackPoint intThe input black point (from 0 to 255).
whitePoint intThe input white point (from 0 to 255).
outputBlack intThe output black point (from 0 to 255).
outputWhite intThe output white point (from 0 to 255).
midtone floatThe value of gamma correction.
Applies a Gaussian blur to this GrayscaleBitmap.
public void ApplyGaussianBlur(byte borderColor, int radius = 9, GaussianBlurBorderMode borderMode = GaussianBlurBorderMode.Default)
borderColor byteThe color used to blend with the edge pixels of the image.
radius intThe radius of the blur, in pixels.
borderMode GaussianBlurBorderModeThe mapping mode for the pixels outside of the border.
Applies a Gaussian blur to this GrayscaleBitmap.
public void ApplyGaussianBlur(int radius = 9, GaussianBlurBorderMode borderMode = GaussianBlurBorderMode.Default)
radius intThe radius of the blur, in pixels.
borderMode GaussianBlurBorderModeThe mapping mode for the pixels outside of the border.
When applied to a grayscale mask built from a color image using the ToGrayscaleBitmap(ColorChannel, bool) method, modifies it so that the result can be used as a transparency mask to produce Glow or Soft Edges effect.
public void ApplyGlow(int infRadius = 4, int blurRadius = 6)
infRadius intThe radius of inflation (positive, glow) or deflation (negative, soft edges), in pixels.
blurRadius intThe radius of Gaussian blur, in pixels.
Applies a license key to an instance of GrayscaleBitmap.
public void ApplyLicenseKey(string key)
key stringThe license key to set.
Modifies pixel intensities such that available range of values (0..255) is fully covered.
public void AutoContrast()
Modifies pixel intensities, clipping extremely low and extremely high values, such that available range of values (0..255) is fully covered.
public void AutoContrast(float lowClipPercent, float highClipPercent)
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.
Clears the GrayscaleBitmap with the specified value (from 0 to 255).
public void Clear(int value, Rectangle rect)
value intThe value (from 0 to 255) to fill the image.
rect System.Drawing.RectangleThe target rectangle of the GrayscaleBitmap.
Clears the GrayscaleBitmap with the specified value (from 0 to 255).
public void Clear(int value)
value intThe value (from 0 to 255) to fill the image.
Creates a new GrayscaleBitmap with a fragment of the image.
public GrayscaleBitmap Clip(Rectangle rect, bool metadataOnly = false)
rect System.Drawing.RectangleClipping rectangle of the source image to be extracted as a new GrayscaleBitmap.
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 GrayscaleBitmap. If true, the pixel data of the resulting GrayscaleBitmap remain uninitialized.
Creates a new GrayscaleBitmap with a copy of the image.
public GrayscaleBitmap 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 GrayscaleBitmap. If true, the pixel data of the resulting GrayscaleBitmap remain uninitialized.
Clean up any resources being used.
public void Dispose()
Performs cleanup operations on managed and unmanaged resources.
protected virtual void Dispose(bool disposing)
disposing boolPerforms cleanup operations on unmanaged resources.
protected ~GrayscaleBitmap()
Inverts the pixel colors from black to white and vice versa.
public void InvertColors()
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.
Changes pixel format from 8 bits per pixel to lower value with two-dimensional error diffusion.
public void ShrinkPixelFormat(int bitsInPixel, DitheringMethod ditheringMethod)
bitsInPixel intThe target number of bits per pixel (from 1 to 8).
ditheringMethod DitheringMethodThe method of two-dimensional error diffusion dithering.
Creates an instance of the GcBitmap class from the current GrayscaleBitmap.
public GcBitmap ToGcBitmap()
Copies the image into an existing instance of GcBitmap.
public void ToGcBitmap(GcBitmap bmp, bool cloneExif)
bmp GcBitmapThe target GcBitmap object.
cloneExif boolSpecifies whether the Exif metadata should be cloned (if exist), not just copied as a reference.
Converts an existing instance of GcBitmap to a semi-transparent bitmap representing the current GrayscaleBitmap.
This method treats the current GrayscaleBitmap as a transparency mask, regardless of the TransparencyMask property value.
public void ToShadowBitmap(GcBitmap bmp, Color shadowColor, float opacityFactor = 1, bool zeroIsOpaque = false)
bmp GcBitmapThe target GcBitmap object.
shadowColor System.Drawing.ColorThe color to fill opaque pixels of the target bitmap.
opacityFactor floatAdditional factor to scale the alpha channel.
zeroIsOpaque boolSpecifies whether zero values correspond to fully opaque (true) or fully transparent (false) pixels.
Creates a semi-transparent GcBitmap from the current GrayscaleBitmap.
This method treats the current GrayscaleBitmap as a transparency mask, regardless of the TransparencyMask property value.
public GcBitmap ToShadowBitmap(Color shadowColor, float opacityFactor = 1, bool zeroIsOpaque = false)
shadowColor System.Drawing.ColorThe color to fill opaque pixels of the target bitmap.
opacityFactor floatAdditional factor to scale the alpha channel.
zeroIsOpaque boolSpecifies whether zero values correspond to fully opaque (true) or fully transparent (false) pixels.