[]
        
(Showing Draft Content)

GrapeCity.Documents.Imaging.GrayscaleBitmap

Class GrayscaleBitmap

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

Represents a grayscale image or transparency mask with 8 bits per pixel.

public class GrayscaleBitmap : IImage, IDisposable
Inheritance
object
GrayscaleBitmap
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

GrayscaleBitmap(byte[], int, int, bool, bool, float, float)

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)

Parameters

pixelData byte[]

The pixel data to be attached to a GrayscaleBitmap.

pixelWidth int

The width of the image, in pixels.

pixelHeight int

The height of the image, in pixels.

transparencyMask bool

If true, the image is used to define an irregularly shaped region of another image.

whiteIsZero bool

If true, specifies that 0 is imaged as white and 255 is imaged as black.

dpiX float

The horizontal dpi of the image.

dpiY float

The vertical dpi of the image.

GrayscaleBitmap(int, int, bool, bool, float, float)

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)

Parameters

pixelWidth int

The width of the image, in pixels.

pixelHeight int

The height of the image, in pixels.

transparencyMask bool

If true, the image is used to define an irregularly shaped region of another image.

whiteIsZero bool

If true, specifies that 0 is imaged as white and 255 is imaged as black.

dpiX float

The horizontal dpi of the image.

dpiY float

The vertical dpi of the image.

GrayscaleBitmap(IntPtr, int, int, bool, bool, float, float)

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)

Parameters

pixelData System.IntPtr

The pixel data to be attached to a GrayscaleBitmap.

pixelWidth int

The width of the image, in pixels.

pixelHeight int

The height of the image, in pixels.

transparencyMask bool

If true, the image is used to define an irregularly shaped region of another image.

whiteIsZero bool

If true, specifies that 0 is imaged as white and 255 is imaged as black.

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

IccProfileData

Gets or sets the raw ICC profile data.

public byte[] IccProfileData { get; set; }

Property Value

byte[]

IsDisposed

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

public bool IsDisposed { get; }

Property Value

bool

this[int, int]

Gets or sets a pixel value (from 0 to 255) at the specified coordinates.

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

Parameters

x int

The X coordinate.

y int

The Y coordinate.

Property Value

int

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

RawData

Gets a pointer to the internal binary data.

public IntPtr RawData { get; }

Property Value

System.IntPtr

Rotation

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

public FlipRotateAction Rotation { get; }

Property Value

FlipRotateAction

TransparencyMask

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; }

Property Value

bool

WhiteIsZero

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; }

Property Value

bool

Methods

AdjustLevels(int, int, int, int, 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(int blackPoint, int whitePoint, int outputBlack, int outputWhite, float midtone = 1)

Parameters

blackPoint int

The input black point (from 0 to 255).

whitePoint int

The input white point (from 0 to 255).

outputBlack int

The output black point (from 0 to 255).

outputWhite int

The output white point (from 0 to 255).

midtone float

The value of gamma correction.

ApplyGaussianBlur(byte, int, GaussianBlurBorderMode)

Applies a Gaussian blur to this GrayscaleBitmap.

public void ApplyGaussianBlur(byte borderColor, int radius = 9, GaussianBlurBorderMode borderMode = GaussianBlurBorderMode.Default)

Parameters

borderColor byte

The color used to blend with the edge pixels of the image.

radius int

The radius of the blur, in pixels.

borderMode GaussianBlurBorderMode

The mapping mode for the pixels outside of the border.

ApplyGaussianBlur(int, GaussianBlurBorderMode)

Applies a Gaussian blur to this GrayscaleBitmap.

public void ApplyGaussianBlur(int radius = 9, GaussianBlurBorderMode borderMode = GaussianBlurBorderMode.Default)

Parameters

radius int

The radius of the blur, in pixels.

borderMode GaussianBlurBorderMode

The mapping mode for the pixels outside of the border.

ApplyGlow(int, int)

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)

Parameters

infRadius int

The radius of inflation (positive, glow) or deflation (negative, soft edges), in pixels.

blurRadius int

The radius of Gaussian blur, in pixels.

ApplyLicenseKey(string)

Applies a license key to an instance of GrayscaleBitmap.

public void ApplyLicenseKey(string key)

Parameters

key string

The license key to set.

AutoContrast()

Modifies pixel intensities such that available range of values (0..255) is fully covered.

public void AutoContrast()

AutoContrast(float, float)

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)

Parameters

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.

Clear(int, Rectangle)

Clears the GrayscaleBitmap with the specified value (from 0 to 255).

public void Clear(int value, Rectangle rect)

Parameters

value int

The value (from 0 to 255) to fill the image.

rect System.Drawing.Rectangle

The target rectangle of the GrayscaleBitmap.

Clear(int)

Clears the GrayscaleBitmap with the specified value (from 0 to 255).

public void Clear(int value)

Parameters

value int

The value (from 0 to 255) to fill the image.

Clip(Rectangle, bool)

Creates a new GrayscaleBitmap with a fragment of the image.

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

Parameters

rect System.Drawing.Rectangle

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

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 GrayscaleBitmap. If true, the pixel data of the resulting GrayscaleBitmap remain uninitialized.

Returns

GrayscaleBitmap

Clone(bool, bool)

Creates a new GrayscaleBitmap with a copy of the image.

public GrayscaleBitmap 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 GrayscaleBitmap. If true, the pixel data of the resulting GrayscaleBitmap remain uninitialized.

Returns

GrayscaleBitmap

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

~GrayscaleBitmap()

Performs cleanup operations on unmanaged resources.

protected ~GrayscaleBitmap()

InvertColors()

Inverts the pixel colors from black to white and vice versa.

public void InvertColors()

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.

ShrinkPixelFormat(int, DitheringMethod)

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

public void ShrinkPixelFormat(int bitsInPixel, DitheringMethod ditheringMethod)

Parameters

bitsInPixel int

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

ditheringMethod DitheringMethod

The method of two-dimensional error diffusion dithering.

ToGcBitmap()

Creates an instance of the GcBitmap class from the current GrayscaleBitmap.

public GcBitmap ToGcBitmap()

Returns

GcBitmap

A new instance of the GcBitmap class.

ToGcBitmap(GcBitmap, bool)

Copies the image into an existing instance of GcBitmap.

public void ToGcBitmap(GcBitmap bmp, bool cloneExif)

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.

ToShadowBitmap(GcBitmap, Color, float, bool)

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)

Parameters

bmp GcBitmap

The target GcBitmap object.

shadowColor System.Drawing.Color

The color to fill opaque pixels of the target bitmap.

opacityFactor float

Additional factor to scale the alpha channel.

zeroIsOpaque bool

Specifies whether zero values correspond to fully opaque (true) or fully transparent (false) pixels.

ToShadowBitmap(Color, float, bool)

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)

Parameters

shadowColor System.Drawing.Color

The color to fill opaque pixels of the target bitmap.

opacityFactor float

Additional factor to scale the alpha channel.

zeroIsOpaque bool

Specifies whether zero values correspond to fully opaque (true) or fully transparent (false) pixels.

Returns

GcBitmap

The newly created GcBitmap.