Java ESCPOS打印机图像输出故障

Java ESCPOS打印机图像输出故障,java,printing,escpos,Java,Printing,Escpos,我正在做一个项目,它从一个通用源读取数据,使用swing生成一个图像,然后将图像(一行图像)转换为escpos命令并发送到打印机 要将图像传输到escpos代码,我使用了材料,但有一点改动: int n = 0; bos.write(printerSchema.getLineSpace24()); for (int y = 0; y < image.length; y += 24) {

我正在做一个项目,它从一个通用源读取数据,使用swing生成一个图像,然后将图像(一行图像)转换为escpos命令并发送到打印机

要将图像传输到escpos代码,我使用了材料,但有一点改动:

            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++;

将问题定位到零件上

如果(n==2){ write(printerSchema.getCutPaper()); } 前面的线没有画出来

你可以用 使用提要打印图像时,效果会很好,如下所示:

            /*
             * 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);


请注意,剪纸的代码是错误的,1B是27位小数,所以它应该是{27,86,1}。我的错在那里。实际的命令是十六进制的“1D56M”,或者是整数中的“2986M”。看起来真不错。恐怕我不能再测试这个了(换工作了)。不过还是要谢谢你
            /*
             * 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);