# glaciall-bitmap

> Manipulate bitmap image with pure JavaScript, and can be base64 format to display on web

Latest version **1.1.0** (published 2020-04-21) · SEE LICENSE IN LICENSE license · 0 weekly downloads

## Install

```sh
npm install glaciall-bitmap
pnpm add glaciall-bitmap
yarn add glaciall-bitmap
bun add glaciall-bitmap
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2020-04-21 |
| First published | 2020-04-21 |
| Weekly downloads | 0 |
| License | SEE LICENSE IN LICENSE |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 21.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | flyskywhy |
| Keywords | base64, bitmap, bmp, image, jsbitmap, react, rgb |

## Links

- npm: https://www.npmjs.com/package/glaciall-bitmap
- Repository: https://github.com/flyskywhy/jsBitmap
- Homepage: https://github.com/flyskywhy/jsBitmap#readme
- Issues: https://github.com/flyskywhy/jsBitmap/issues
- npm.io page: https://npm.io/package/glaciall-bitmap

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2020-04-21
- 1.0.0 — 2020-04-21

## README

jsBitmap
========

基于Javascript的bitmap处理，并且将位图输出为base64编码以便于浏览器进行显示，代码超精简，低内存占用。

Install
========
```shell
npm install --save glaciall-bitmap
```

Usage
========
```
import {
    BitMap,
} from 'glaciall-bitmap';

export class YourReactClass extends React.PureComponent {
    constructor(props, ctx) {
        super(props, ctx);
        this.bmp = new BitMap();
        this.bmp.fromBase64(props.base64Bmp.replace(/^data:image\/bmp;base64,/, ''));
    }
}
```

API参考
========
一、Bitmap.create(width, height, bgcolor)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;创建一个width x height像素大小的位图，底色为bgcolor所代表的颜色。<br/>
&nbsp;&nbsp;&nbsp;&nbsp;如：bitmap.create(10, 10, 0xff0000);   // 创建一个10 x 10像素的底色为红色的位图<br/><br/>

二、Bitmap.toBase64()<br/>
&nbsp;&nbsp;&nbsp;&nbsp;将位图输出为base64编码的带datauri头（data:image/bmp;base64,）的字符串，以便于在浏览器里显示。<br/>
&nbsp;&nbsp;&nbsp;&nbsp;如：document.getElementById('img1').src = bitmap.toBase64();<br/><br/>

三、Bitmap.fromBase64()<br/>
&nbsp;&nbsp;&nbsp;&nbsp;自图像的BASE64编码中恢复位图数据，目前只支持24位色的BMP位图数据。<br/>
&nbsp;&nbsp;&nbsp;&nbsp;如：bitmap.fromBase64('Qk06AAAAAAAAADYAAAAoAAAAAQAAAAEAAAABABgAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==');<br/><br/>

四、Bitmap.setBitmapBytes(val, idx, length)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;修改bitmap位图数据的第idx位置起的length字节为val值。<br/><br/>

五、Bitmap.getBitmapBytes(idx, length)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;获取bitmap位图数据的第idx位置起的length个字节的值，返回值为数组。<br/><br/>

六、Bitmap.setHeaderValue(attribute, headerValue)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;设置attribute头属性的值为headerValue，attribute必须为BitMapFormat的成员属性，需要提供offset、length等属性值。<br/>
&nbsp;&nbsp;&nbsp;&nbsp;如：bitmap.setHeaderValue(BitmapFormat.biWidth, 500);    // 设置位图的宽度为500像素值<br/><br/>

七、Bitmap.getHeaderValue(attribute)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;获取位图attribute头属性的值，attribute必须为BitmapFormat的成员属性，需要提供offset、length等属性值，返回的是经过Endian转换后的实际整数值。<br/><br/>

八、Bitmap.setPixel(x, y, color)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;设置位图的(x, y)位置的像素值为color。<br/><br/>

九、Bitmap.getPixel(x, y)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;获取位图的(x, y)位置的RGB值，返回的内容为[ rr, gg, bb ]的数组内容<br/>

十、Bitmap.getRgbRect()<br/>
&nbsp;&nbsp;&nbsp;&nbsp;预先使用 getPixel() 生成RGB数值的二维数组，便于调用者稍后以之快速定位像素，因为查表的速度远高于即时计算 getPixel()<br/>
&nbsp;&nbsp;&nbsp;&nbsp;返回的内容为[ [0xrrggbb, 0xrrggbb], [0xrrggbb, 0xrrggbb] ]的[[x维],[x维]]二维数组内容<br/>
&nbsp;&nbsp;&nbsp;&nbsp;如果位图原始数据被比如 setPixel() 修改了，则需要重新调用本函数来更新RGB二维数组<br/>

十一、Bitmap.rgbToHexString(rgb)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;将 0xrrggbb 转换为 '#rrggbb'<br/>


PS
========
[glaciall](https://github.com/glaciall) [authorized](https://github.com/glaciall/jsBitmap/pull/2#issuecomment-566343119) [flyskywhy](https://github.com/flyskywhy) to publish glaciall-bitmap on npm.

---
_Source: https://npm.io/package/glaciall-bitmap · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
