bitmap-to-pwg
v1.0.1
Published
image (bitmap) to image/pwg-raster
Maintainers
Readme
代码移植自 HP 公司的 Java 项目 JIPP: 见:https://github.com/HPInc/jipp
用于将位图数据编码为 pwg(image/pwg-raster) 光栅化文件。
##前端使用例子:
const canvas = document.createElement('canvas');
const img = document.createElement('img');
img.onload = () => {
canvas.width = img.width;
canvas.height = img.height;
const ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
const bitmap = new Int8Array(ctx.getImageData(0, 0, img.width, img.height).data);
const getPixelData = (x, y) => {
const pixel = x + y * img.width;
const i = pixel * 4; // 4, canvas 获取的数据是 rgba 4 byte
return {
r: bitmap[i],
g: bitmap[i + 1],
b: bitmap[i + 2],
};
};
const dpi = 96;
const pwgData = encodePWG(img.width, img.height, ColorSpace.rgb, getPixelData, dpi);
// 后续处理...
// 如:通过 ipp 发送到打印机
};
img.src = './test.png';