【发布时间】: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