# GrayscaleBitmap

## Content

# Class: GrayscaleBitmap

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

## Extends

- [`ObjectBase`](ObjectBase)

## Constructors

### Constructor

```ts
new GrayscaleBitmap(
   width, 
   height, 
   gbProperties?): GrayscaleBitmap;
```

Creates a GrayscaleBitmap instance with optionally initialized pixels.

#### Parameters

##### width

`number`

The grayscale bitmap width, in pixels.

##### height

`number`

The grayscale bitmap height, in pixels.

##### gbProperties?

[`GrayscaleBitmapProperties`](../type-aliases/GrayscaleBitmapProperties)

The settings for creating a grayscale bitmap.

#### Returns

`GrayscaleBitmap`

#### Overrides

```ts
ObjectBase.constructor
```

### Constructor

```ts
new GrayscaleBitmap(
   om, 
   width, 
   height, 
   gbProperties?): GrayscaleBitmap;
```

Creates a GrayscaleBitmap instance with optionally initialized pixels.

#### Parameters

##### om

[`ObjectManager`](ObjectManager)

An object manager that controls the lifetime of the GrayscaleBitmap object.

##### width

`number`

The grayscale bitmap width, in pixels.

##### height

`number`

The grayscale bitmap height, in pixels.

##### gbProperties?

[`GrayscaleBitmapProperties`](../type-aliases/GrayscaleBitmapProperties)

The settings for creating a grayscale bitmap.

#### Returns

`GrayscaleBitmap`

#### Overrides

```ts
ObjectBase.constructor
```

## Accessors

### height

#### Get Signature

```ts
get height(): number;
```

Gets the height of the GrayscaleBitmap, in pixels.

##### Returns

`number`

***

### id

#### Get Signature

```ts
get id(): number;
```

Gets the reference to the object.

##### Returns

`number`

#### Inherited from

[`ObjectBase`](ObjectBase).[`id`](ObjectBase#id)

***

### om

#### Get Signature

```ts
get om(): ObjectManager;
```

Gets the owner [ObjectManager](ObjectManager) instance.

##### Returns

[`ObjectManager`](ObjectManager)

#### Inherited from

[`ObjectBase`](ObjectBase).[`om`](ObjectBase#om)

***

### transparencyMask

#### Get Signature

```ts
get transparencyMask(): boolean;
```

Gets or sets a value indicating whether the image is used to define an alpha mask of another image.

##### Returns

`boolean`

#### Set Signature

```ts
set transparencyMask(value): void;
```

Gets or sets a value indicating whether the image is used to define an alpha mask of another image.

##### Parameters

###### value

`boolean`

##### Returns

`void`

***

### whiteIsZero

#### Get Signature

```ts
get whiteIsZero(): boolean;
```

Gets or sets a value specifying whether 0 represents white and 255 represents black (if true) or vice versa (if false).

##### Returns

`boolean`

#### Set Signature

```ts
set whiteIsZero(value): void;
```

Gets or sets a value specifying whether 0 represents white and 255 represents black (if true) or vice versa (if false).

##### Parameters

###### value

`boolean`

##### Returns

`void`

***

### width

#### Get Signature

```ts
get width(): number;
```

Gets the width of the GrayscaleBitmap, in pixels.

##### Returns

`number`

## Methods

### adjustLevels()

```ts
adjustLevels(
   blackPoint, 
   whitePoint, 
   outputBlack, 
   outputWhite, 
   midtone?): void;
```

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).

#### Parameters

##### blackPoint

`number`

The input black point (between 0 and 255).

##### whitePoint

`number`

The input white point (between 0 and 255).

##### outputBlack

`number`

The output black point (between 0 and 255).

##### outputWhite

`number`

The output white point (between 0 and 255).

##### midtone?

`number`

The value of gamma correction.

#### Returns

`void`

***

### applyGaussianBlur()

```ts
applyGaussianBlur(
   radius?, 
   borderMode?, 
   borderColor?): void;
```

Applies a Gaussian blur to this GrayscaleBitmap.

#### Parameters

##### radius?

`number`

The radius of the blur, in pixels.

##### borderMode?

[`GaussianBlurBorderMode`](../enumerations/GaussianBlurBorderMode)

The mapping mode for the pixels outside of the border, "RepeatEdge" if null.

##### borderColor?

`number`

The color used to blend with the edge pixels of the image (between 0 and 255).

#### Returns

`void`

***

### applyGlow()

```ts
applyGlow(infRadius?, blurRadius?): void;
```

When applied to a grayscale mask built from a color image using the [Bitmap#toGrayscaleBitmap](Bitmap#tograyscalebitmap) method, modifies it
so that the result can be used as a transparency mask to produce "Glow" or "Soft Edges" effects.

#### Parameters

##### infRadius?

`number`

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

##### blurRadius?

`number`

The radius of Gaussian blur, in pixels.

#### Returns

`void`

***

### autoContrast()

#### Call Signature

```ts
autoContrast(): void;
```

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

##### Returns

`void`

#### Call Signature

```ts
autoContrast(lowClipFraction, highClipFraction): void;
```

Modifies pixel intensities, clipping extremely low and extremely high values,
such that available range of values (0..255) is fully covered.

##### Parameters

###### lowClipFraction

`number`

The fraction of extremely low values to be clipped, not greater than 0.1.

###### highClipFraction

`number`

The fraction of extremely high values to be clipped, not greater than 0.1.

##### Returns

`void`

***

### clear()

```ts
clear(value, bounds?): void;
```

Clears the GrayscaleBitmap with the specified value.

#### Parameters

##### value

`number`

The value (between 0 and 255) to fill the image.

##### bounds?

[`Bounds`](../type-aliases/Bounds)

The target rectangle of the GrayscaleBitmap.

#### Returns

`void`

***

### clip()

#### Call Signature

```ts
clip(
   x, 
   y, 
   width, 
   height, 
   metadataOnly?): GrayscaleBitmap;
```

Creates a new GrayscaleBitmap with a fragment of the image.

##### Parameters

###### x

`number`

The X coordinate of the clipping rectangle.

###### y

`number`

The Y coordinate of the clipping rectangle.

###### width

`number`

The width of the clipping rectangle.

###### height

`number`

The height of the clipping rectangle.

###### metadataOnly?

`boolean`

Specifies whether to copy the image metadata only, not actual pixel data. The default is false.

##### Returns

`GrayscaleBitmap`

A new GrayscaleBitmap with a fragment of the source image.

#### Call Signature

```ts
clip(bounds, metadataOnly?): GrayscaleBitmap;
```

Creates a new GrayscaleBitmap with a fragment of the image.

##### Parameters

###### bounds

[`Bounds`](../type-aliases/Bounds)

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

###### metadataOnly?

`boolean`

Specifies whether to copy the image metadata only, not actual pixel data. The default is false.

##### Returns

`GrayscaleBitmap`

A new GrayscaleBitmap with a fragment of the source image.

***

### clone()

```ts
clone(metadataOnly?): GrayscaleBitmap;
```

Creates a new GrayscaleBitmap with a copy of the image.

#### Parameters

##### metadataOnly?

`boolean`

specifies whether to copy the image metadata only, not actual pixel data.

#### Returns

`GrayscaleBitmap`

A new instance of the GrayscaleBitmap.

***

### free()

```ts
free(): void;
```

Detaches the object from the [ObjectManager](ObjectManager) and deallocates its memory, if possible.

#### Returns

`void`

#### Inherited from

[`ObjectBase`](ObjectBase).[`free`](ObjectBase#free)

***

### invertColors()

```ts
invertColors(): void;
```

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

#### Returns

`void`

***

### rebind()

```ts
rebind(omTo): void;
```

Rebinds the object from the current [ObjectManager](ObjectManager) to the specified one.

#### Parameters

##### omTo

[`ObjectManager`](ObjectManager)

The new [ObjectManager](ObjectManager) for the object.

#### Returns

`void`

#### Inherited from

[`ObjectBase`](ObjectBase).[`rebind`](ObjectBase#rebind)

***

### toBitmap()

```ts
toBitmap(): Bitmap;
```

Creates a [Bitmap](Bitmap) instance from the current GrayscaleBitmap.

#### Returns

[`Bitmap`](Bitmap)

A new instance of the [Bitmap](Bitmap) class.

***

### toShadowBitmap()

```ts
toShadowBitmap(
   shadowColor, 
   opacityFactor?, 
   zeroIsOpaque?): Bitmap;
```

Creates a semi-transparent [Bitmap](Bitmap) from the current GrayscaleBitmap.
This method treats the current GrayscaleBitmap as a transparency mask, regardless of the transparencyMask property value.

#### Parameters

##### shadowColor

[`Color`](../type-aliases/Color)

The color to fill opaque pixels of the target bitmap.

##### opacityFactor?

`number`

Additional factor to scale the alpha channel.

##### zeroIsOpaque?

`boolean`

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

#### Returns

[`Bitmap`](Bitmap)

A new instance of the [Bitmap](Bitmap) class.
