首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ESCPOS打印机图像显示故障

ESCPOS打印机图像显示故障
EN

Stack Overflow用户
提问于 2017-02-21 07:41:00
回答 1查看 1.4K关注 0票数 2

我正在进行一个项目,该项目从通用源读取数据,使用swing生成图像,而不是将图像(一行图像)转换为托管命令并将其发送到打印机。

为了将图像传输到escpos代码,我使用了图像打印材料,但做了一些小改动:

代码语言:javascript
复制
            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++;

修改是一个“剪纸命令”,在绘制第二行之后(实际上,打印机在切割器和打印机头之间有很大的空间)。

一切看起来都很好,但有时我会随机地收到第二行缺失(总是在剪纸命令之前),有时是缺少空格(第一行和第三行只是在一起),有时是空白。

打印机: Sam4s Giant-100命令:

代码语言:javascript
复制
    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

将问题定位在零件上

如果(n == 2) { bos.write(printerSchema.getCutPaper());}它之前的线没有绘制。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-25 18:56:45

您可以使用咖啡图书馆和使用提要的打印图像可以这样工作:

代码语言:javascript
复制
            /*
             * 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);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42361328

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档