我正在尝试使用BufferedImage将图像(jpeg)转换为ASCII HEX表示。 这背后的想法是我将直接在ZPL代码中使用HEX表示。
我想到的整个过程如下:
到目前为止,我已经能够使用以下代码实现前两个步骤。
try {
BufferedImage img = ImageIO.read(ImageToHex.class.getResourceAsStream("Input.JPG"));
final byte[] pixels = ((DataBufferByte) img.getRaster().getDataBuffer()).getData();
System.out.println("Pixels : " + pixels);
final int width = img.getWidth();
System.out.println("Width : " + width);
final int height = img.getHeight();
System.out.println("Height : " + height);
int[][] result = new int[height][width];
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
result[row][col] = img.getRGB(col, row);
}
}
System.out.println("Result: " + result);
} catch (IOException e) {
e.printStackTrace();
}
不确定如何继续获取输入图像的最终十六进制表示。
注意:有一些斑马特定的库将图像转换为GRF(这是十六进制表示),但截至目前我还没有任何计划使用它们。
感谢对此的任何意见。