【问题标题】:Java ESC/POS Image full width PrintingJava ESC/POS 图像全幅打印
【发布时间】:2021-12-12 17:24:05
【问题描述】:

我正在尝试使用 this blog 中给出的 Esc/Pos 命令打印图像。它打印得很好,但我想将图像对齐到中心并适合纸张尺寸。 我打印这张图片:

输出如下:

我的代码和this blog post一样 但我将getPixelsSlow(BufferedImage image) 方法更改为这两种方法,因为Android 没有BufferedImage 类。

private int[][] getPixelsSlow(Bitmap image) {
  int width = image.getWidth();
  int height = image.getHeight();
  int[][] result = new int[height][width];
  for (int row = 0; row < height; row++) {
    for (int col = 0; col < width; col++) {
      result[row][col] = getRGB(image, col, row);
     }
   }

  return result;
}

private int getRGB(Bitmap bmpOriginal, int col, int row) {
   // get one pixel color
   int pixel = bmpOriginal.getPixel(col, row);
   // retrieve color of all channels
   int R = Color.red(pixel);
   int G = Color.green(pixel);
   int B = Color.blue(pixel);
   return Color.rgb(R, G, B);
}

如何打印全宽图像?谢谢!

【问题讨论】:

    标签: java image printing escpos


    【解决方案1】:

    如果你在网上搜索,你会发现一个库或方法可以转换图像数据的垂直和水平大小,并根据要打印的纸张的最大宽度进行转换。

    但是,由于原始数据的大小只有 113 宽和 48 高,这些转换会导致锯齿状和缺乏艺术性。

    最好事先创建和使用与要打印的纸张宽度相匹配的图像数据。

    例如,如果你使用 GIMP 将宽度放大到 512,高度放大到 217 为 JPEG,会如下。

    或者如果你用Windows Paint把它放大到同样的大小,然后再转换成单色二进制格式的BMP,会如下。

    如果你从一开始就指定宽度512来创建一个设计,而不是执行这样的转换,它对于营销等会更加美观和有效。

    【讨论】:

      猜你喜欢
      • 2020-02-11
      • 2018-08-29
      • 2013-11-23
      • 1970-01-01
      • 2013-07-01
      • 2015-09-09
      • 2014-12-14
      • 2018-11-09
      • 2018-12-18
      相关资源
      最近更新 更多