Skip to content

@mbtech-nl/bitmap / cropBitmap

Function: cropBitmap()

ts
function cropBitmap(
   bitmap: LabelBitmap, 
   x: number, 
   y: number, 
   widthPx: number, 
   heightPx: number): LabelBitmap;

Defined in: transform.ts:206

Extract a rectangular sub-region from a bitmap.

Parameters

ParameterTypeDescription
bitmapLabelBitmapSource bitmap.
xnumberLeft edge of crop, in pixels.
ynumberTop edge of crop, in pixels.
widthPxnumberCrop width in pixels (≥ 1).
heightPxnumberCrop height in pixels (≥ 1).

Returns

LabelBitmap

A new bitmap containing the cropped region.

Throws

If the region is out of bounds or has non-positive dimensions.

Example

ts
const header = cropBitmap(label, 0, 0, label.widthPx, 32);

Released under the MIT License.