Bitmap object
Bitmap()
and $Bitmap()
shortcut#
#
Syntax#
Examples- JavaScript (CJS)
- TypeScript (strict)
#
ParametersName | R/O | Type | Default Value | Description |
---|---|---|---|---|
bin_bitmap_list | Required | array of strings | N/A | Binary bitmap data, which is a array of '0' /'1' /'2' strings |
#
Return valueBitmap object
#
DescriptionInitialize a Bitmap object. Load binary bitmap data (array of strings).
The shortcut $Bitmap(bin_bitmap_list)
is equivalent to new Bitmap(bin_bitmap_list)
, use it for convenience.
.bindata
#
#
Syntax#
Examples- JavaScript (CJS)
- TypeScript (strict)
#
Typearray of strings
#
DescriptionThis attribute of a Bitmap object represents the raw binary data of the bitmap.
note
If you want to get the data, use API methods .todata() or .tobytes() instead.
.width()
#
#
Syntax#
Examples- JavaScript (CJS)
- TypeScript (strict)
#
ParametersNo parameters
#
Return value(number) Width of the bitmap
#
DescriptionGet the width of the bitmap.
.height()
#
#
Syntax#
Examples- JavaScript (CJS)
- TypeScript (strict)
#
ParametersNo parameters
#
Return value(number) Height of the bitmap
#
DescriptionGet the height of the bitmap.
.clone()
#
#
Syntax#
Examples- JavaScript (CJS)
- TypeScript (strict)
#
ParametersNo parameters
#
Return value(Bitmap object) A deep copy of the original Bitmap object
#
DescriptionGet a deep copy / clone of the Bitmap object.
.crop()
#
#
Syntax#
Examples- JavaScript (CJS)
- TypeScript (strict)
Before:
After:
#
ParametersName | R/O | Type | Default Value | Description |
---|---|---|---|---|
w | Required | number | N/A | Width of the new bitmap |
h | Required | number | N/A | Height of the new bitmap |
xoff | Optional | number | 0 | Relative position in x (right) direction of the new starting (bottom-left) point from the old one |
yoff | Optional | number | 0 | Relative position in y (top) direction of the new starting (bottom-left) point from the old one |
#
Return valueThe Bitmap object itself, which now has only the specified area as its .bindata
.
(Consider to use .clone()
first, if you want to maintain the original copy of the Bitmap object)
#
DescriptionCrop and/or extend the bitmap.
.overlay()
#
#
Syntax#
Examples- JavaScript (CJS)
- TypeScript (strict)
#
ParametersName | R/O | Type | Default Value | Description |
---|---|---|---|---|
bitmap | Required | Bitmap object | N/A | The incoming bitmap to overlay over the current one |
#
Return valueThe Bitmap object itself, which now has the combined bitmap as its .bindata
.
#
DescriptionOverlay another bitmap over the current one.
note
This method mutates the Bitmap object. Consider to use .clone() first, if you want to maintain the original copy of the Bitmap object.
Bitmap.concatall()
#
#
Syntax#
ExamplesClick to see the `.toString()` output of the result above
Click to see the `.toString()` output of the result above
Click to see the `.toString()` output of the result above
Click to see the `.toString()` output of the result above
Click to see the `.toString()` output of the result above
#
ParametersName | R/O | Type | Default Value | Description |
---|---|---|---|---|
bitmaplist | Required | array of Bitmap objects | N/A | array of bitmaps to concatenate |
(in options ) direction | Optional | number | 1 | 1 : right0 : down2 : left-1 : up |
(in options ) align | Optional | number | 1 | If horizontal (right (1 ) or left (2 )) direction:1 : bottom0 : topIf vertical (down ( 0 ) or up (-1 )) direction:1 : left0 : right |
(in options ) offsetlist | Optional | array of numbers | None | array of spacing offsets between every two glyphs: [offset_between_0_and_1, offset_between_1_and_2, ..., offset_between_2nd_last_and_last] . len(offsetlist) should be equal to len(bitmaplist)-1 . If None , then all offsets are 0 |
#
Return valueBitmap object
#
DescriptionConcatenate all Bitmap objects in a array.
This is a class / static method, meaning you need to call the method on the Bitmap
class: Bitmap.concatall()
.concat()
#
#
Syntax#
Examples- JavaScript (CJS)
- TypeScript (strict)
#
ParametersName | R/O | Type | Default Value | Description |
---|---|---|---|---|
bitmap | Required | Bitmap object | N/A | Bitmap to concatenate |
(in options ) offset | Required | number | 0 | Spacing offset between the glyphs. See also offsetlist parameter in Bitmap.concatall() |
For the rest of the parameters (direction
, align
in options
), see Bitmap.concatall()
's "Parameters" section
#
Return valueThe Bitmap object itself, which now has the combined bitmap as its .bindata
.
#
DescriptionConcatenate another Bitmap objects to the current one.
It is similar to Bitmap.concatall([bitmap1, bitmap2])
, but update the current Bitmap object and return it, instead of creating a new one like the other two methods.
note
This method mutates the Bitmap object. If you want to maintain the original copy of the Bitmap object, consider to use Bitmap.concatall() or .clone() first.
.enlarge()
#
#
Syntax#
Examples- JavaScript (CJS)
- TypeScript (strict)
Before:
After:
#
ParametersName | R/O | Type | Default Value | Description |
---|---|---|---|---|
x | Optional | number | 1 | Multiplier in x (right) direction |
y | Optional | number | 1 | Multiplier in y (top) direction |
#
Return valueThe Bitmap object itself, which now has the enlarged bitmap as its .bindata
.
#
DescriptionEnlarge a Bitmap object, by multiplying every pixel in x (right) direction and in y (top) direction.
.replace()
#
#
Syntax#
Examples- JavaScript (CJS)
- TypeScript (strict)
#
ParametersName | R/O | Type | Default Value | Description |
---|---|---|---|---|
substr | Required | strings | N/A | Substring to be replaced |
newsubstr | Required | strings | N/A | New substring as the replacement |
#
Return valueThe Bitmap object itself, which now has the altered bitmap as its .bindata
.
#
DescriptionReplace a string by another in the bitmap. Because the bitmap's data is stored as a array of '0'
/'1'
/'2'
strings (e.g. ['0211','1010','0200']
), you can replace a substring (e.g. '2'
by '1'
) in it.
.shadow()
#
#
Syntax#
Examples- JavaScript (CJS)
- TypeScript (strict)
Before:
After:
#
ParametersName | R/O | Type | Default Value | Description |
---|---|---|---|---|
xoff | Optional | number | 1 | Shadow's offset in x (right) direction |
yoff | Optional | number | -1 | Shadow's offset in y (top) direction |
#
Return valueThe Bitmap object itself, which now has a bitmap of the original shape with its shadow as the Bitmap object's .bindata
.
#
DescriptionAdd shadow to the shape in the bitmap.
The shadow will be filled by '2'
s.
Default parameters (xoff=1, yoff=-1
) mean add a shadow which is 1 pixel right and 1 pixel bottom to the original shape.
.glow()
#
#
Syntax#
Examples- JavaScript (CJS)
- TypeScript (strict)
Before:
After (default mode 0
):
After (mode 1
):
#
ParametersName | R/O | Type | Default Value | Description |
---|---|---|---|---|
mode | Optional | integer | 0 | Mode. Corner pixels will not be filled in default mode 0 but will in mode 1 |
#
Return valueThe Bitmap object itself, which now has a bitmap of the original shape with glow effect as the Bitmap object's .bindata
.
#
DescriptionAdd glow effect to the shape in the bitmap.
The glowing area is one pixel up, right, bottom and left to the original pixels (corners will not be filled in default mode 0 but will in mode 1), and will be filled by '2'
s.
.bytepad()
#
#
Syntax#
Examples- JavaScript (CJS)
- TypeScript (strict)
#
ParametersName | R/O | Type | Default Value | Description |
---|---|---|---|---|
bits | Optional | number | 8 | Each line should be padded to multiple of how many bits/pixels |
#
Return valueThe Bitmap object itself, which now has the altered bitmap as its .bindata
.
#
DescriptionPad each line (row) to multiple of 8 (or other numbers) bits/pixels, with '0'
s.
Do this before using the bitmap for a glyph in a BDF font: per BDF spec, if the bit/pixel count in a line is not multiple of 8, the line needs to be padded on the right with 0s to the nearest byte (that is, multiple of 8).
Parameter bits
is 8
by default because 1 byte = 8 bits, you can change it if you want to use other unconventional, off-spec values, such as 4 (half a byte).
.todata()
#
#
Syntax#
Examples- JavaScript (CJS)
- TypeScript (strict)
#
ParametersName | R/O | Type | Default Value | Description |
---|---|---|---|---|
datatype | Optional | See below | 1 | Output data type. See below |
datatype
: output data type:
0
: binary-encoded multi-line string. e.g.'00010\n11010\n00201'
1
: array of binary-encoded strings. e.g.['00010','11010','00201']
2
: array of arrays of numbers0
or1
(or2
sometimes). e.g.[[0,0,0,1,0],[1,1,0,1,0],[0,0,2,0,1]]
3
: array of numbers0
or1
(or2
sometimes) (to be used with.width()
and.height()
). e.g.[0,0,0,1,0,1,1,0,1,0,0,0,2,0,1]
4
: array of lowercase hexadecimal-encoded strings (without'0x'
, padded with leading'0'
s according to width). e.g.['02','1a']
5
: array of numbers. e.g.[2,26]
note
You can't have '2'
s when using datatype
4
or 5
.
#
Return valueBitmap data in the specified type (array or string) and format
#
DescriptionGet the bitmap's data in the specified type and format.
.draw2canvas()
#
#
Syntax#
Examples- JavaScript (CJS)
- TypeScript (strict)
#
ParametersName | R/O | Type | Default Value | Description |
---|---|---|---|---|
context | Required | CanvasContext | N/A | Canvas context, see above example |
pixelcolors | Optional | object | see below | Pixel color map |
By default, parameter pixelcolors
is set to:
'0'
defines background color, '1'
defines foreground color, '2'
defines shadow or glowing effect color. The color can be hex color value (e.g. #000000
), CSS color keyword or anything CanvasRenderingContext2D.fillStyle accepts.
#
Return valueThe Bitmap object itself.
#
DescriptionDraw the bitmap to HTML <canvas>
element.
.toString()
#
#
Syntax#
Examples- JavaScript (CJS)
- TypeScript (strict)
#
Description(string) .toString()
gets a human-readable (multi-line) string representation of the Bitmap object.
The following digits in the bitmap's binary-encoded string array data are replaced in .toString()
's output:
'0'
s are replaced by#
'1'
s are replaced by.
'2'
s are replaced by&
.repr()
#
#
Syntax#
Examples- JavaScript (CJS)
- TypeScript (strict)
#
Description(string) It gets a programmer-readable (multi-line) string representation of the Bitmap object.