title: ESCPOS Printer image out glitches
body: <p>I'm working on a project, that reads the data from a generic source, formes an image using swing, than translates the image(a row of images) into escpos commands and sends it to the printer.</p>
  
  <p>To transfer the image to escpos code i used <a href="http://new-grumpy-mentat.blogspot.com/2014/06/java-escpos-image-printing.html" rel="nofollow noreferrer">java-escpos-image-printing</a> material, but with a minor alteration:</p>
  
  <pre><code>            int n = 0;
              bos.write(printerSchema.getLineSpace24());
              for (int y = 0; y &lt; 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 &amp; image[y].length), (byte) ((0xff00 &amp; image[y].length) &gt;&gt; 8) });
                  for (int x = 0; x &lt; 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++;
  </code></pre>
  
  <p>The alteration is a "cut-paper-command", that should init after the second line is drawn(physically, the printer has a large space between the cutter and the printer head).</p>
  
  <p>All seem to be working fine, but sometimes i randomly recieve a missing second line(always before the cut paper command), sometimes with missing space(the first and third line just get together), and sometimes with a white space.</p>
  
  <p>The printer: Sam4s Giant-100
  Commands: </p>
  
  <pre><code>    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
  </code></pre>
  
  <hr>
  
  <p>Localized the problem to the part</p>
  
  <blockquote>
    <p>if (n == 2) {
                          bos.write(printerSchema.getCutPaper());
                      }
    the line before it isnt drawn.</p>
  </blockquote>