ESCPOS 打印机图像输出故障
ESCPOS Printer image out glitches
我正在做一个项目,它从通用来源读取数据,使用 swing 形成图像,然后将图像(一行图像)转换为 escpos 命令并将其发送到打印机。
为了将图像传输到 escpos 代码,我使用了 java-escpos-image-printing material,但稍作改动:
int n = 0;
bos.write(printerSchema.getLineSpace24());
for (int y = 0; y < image.length; y += 24) {
// Like I said before, when done sending data,
// the printer will resume to normal text printing
if (n == 2) {
bos.write(printerSchema.getCutPaper());
}
bos.write(printerSchema.getImageMode());
// Set nL and nH based on the width of the image
bos.write(new byte[] { (byte) (0x00ff & image[y].length), (byte) ((0xff00 & image[y].length) >> 8) });
for (int x = 0; x < image[y].length; x++) {
// for each stripe, recollect 3 bytes (3 bytes = 24 bits)
bos.write(recollectSlice(y, x, image));
}
// Do a line feed, if not the printing will resume on the same
// line
bos.write(printerSchema.getLineFeed());
n++;
改动是"cut-paper-command",画完第二条线后就开始了(物理上,打印机在切刀和打印头之间有一个很大的space)。
一切似乎都正常,但有时我随机收到缺少的第二行(总是在切纸命令之前),有时缺少 space(第一行和第三行刚好放在一起),并且有时用白色 space.
打印机:Sam4s Giant-100
命令:
INIT_PRINTER = new byte[]{0x1B,0x40},//1B 40 Initialize printer
IMAGE_MODE = new byte[] { 0x1B, 0x2A, 33 }, LINE_FEED = new byte[] { 0x0A },
LINE_SPACE_24 = new byte[] { 0x1B, 0x33, 24 }, LINE_SPACE_30 = new byte[] { 0x1B, 0x33, 30 },
CUT_PAPER = new byte[] { 29, 86, 1 }; // 1B 33 n
将问题定位到零件
if (n == 2) {
bos.write(printerSchema.getCutPaper());
}
the line before it isnt drawn.
您可以使用 escpos-coffee library
并且使用 feed 打印图像可以像这样正常工作:
/*
* to print one image we need to have:
* - one BufferedImage.
* - one bitonal algorithm to define what and how print on image.
* - one image wrapper to determine the command set to be used on
* image printing and how to customize it.
*/
// creating the EscPosImage, need buffered image and algorithm.
URL imageURL = getURL("dog.png");
BufferedImage imageBufferedImage = ImageIO.read(imageURL);
// this wrapper uses esc/pos sequence: "GS 'v' '0'"
RasterBitImageWrapper imageWrapper = new RasterBitImageWrapper();
escpos = new EscPos(new PrinterOutputStream(printService));
escpos.feed(5);
escpos.writeLF("BitonalThreshold()");
// using bitonal threshold for dithering
Bitonal algorithm = new BitonalThreshold();
EscPosImage escposImage = new EscPosImage(imageBufferedImage, algorithm);
escpos.write(imageWrapper, escposImage);
escpos.feed(5);
escpos.cut(EscPos.CutMode.PART);
我正在做一个项目,它从通用来源读取数据,使用 swing 形成图像,然后将图像(一行图像)转换为 escpos 命令并将其发送到打印机。
为了将图像传输到 escpos 代码,我使用了 java-escpos-image-printing material,但稍作改动:
int n = 0;
bos.write(printerSchema.getLineSpace24());
for (int y = 0; y < image.length; y += 24) {
// Like I said before, when done sending data,
// the printer will resume to normal text printing
if (n == 2) {
bos.write(printerSchema.getCutPaper());
}
bos.write(printerSchema.getImageMode());
// Set nL and nH based on the width of the image
bos.write(new byte[] { (byte) (0x00ff & image[y].length), (byte) ((0xff00 & image[y].length) >> 8) });
for (int x = 0; x < image[y].length; x++) {
// for each stripe, recollect 3 bytes (3 bytes = 24 bits)
bos.write(recollectSlice(y, x, image));
}
// Do a line feed, if not the printing will resume on the same
// line
bos.write(printerSchema.getLineFeed());
n++;
改动是"cut-paper-command",画完第二条线后就开始了(物理上,打印机在切刀和打印头之间有一个很大的space)。
一切似乎都正常,但有时我随机收到缺少的第二行(总是在切纸命令之前),有时缺少 space(第一行和第三行刚好放在一起),并且有时用白色 space.
打印机:Sam4s Giant-100 命令:
INIT_PRINTER = new byte[]{0x1B,0x40},//1B 40 Initialize printer
IMAGE_MODE = new byte[] { 0x1B, 0x2A, 33 }, LINE_FEED = new byte[] { 0x0A },
LINE_SPACE_24 = new byte[] { 0x1B, 0x33, 24 }, LINE_SPACE_30 = new byte[] { 0x1B, 0x33, 30 },
CUT_PAPER = new byte[] { 29, 86, 1 }; // 1B 33 n
将问题定位到零件
if (n == 2) { bos.write(printerSchema.getCutPaper()); } the line before it isnt drawn.
您可以使用 escpos-coffee library 并且使用 feed 打印图像可以像这样正常工作:
/*
* to print one image we need to have:
* - one BufferedImage.
* - one bitonal algorithm to define what and how print on image.
* - one image wrapper to determine the command set to be used on
* image printing and how to customize it.
*/
// creating the EscPosImage, need buffered image and algorithm.
URL imageURL = getURL("dog.png");
BufferedImage imageBufferedImage = ImageIO.read(imageURL);
// this wrapper uses esc/pos sequence: "GS 'v' '0'"
RasterBitImageWrapper imageWrapper = new RasterBitImageWrapper();
escpos = new EscPos(new PrinterOutputStream(printService));
escpos.feed(5);
escpos.writeLF("BitonalThreshold()");
// using bitonal threshold for dithering
Bitonal algorithm = new BitonalThreshold();
EscPosImage escposImage = new EscPosImage(imageBufferedImage, algorithm);
escpos.write(imageWrapper, escposImage);
escpos.feed(5);
escpos.cut(EscPos.CutMode.PART);