[英]Android - How can I print an image (Raster) on a Bluetooth printer (X330)?
I have the thermal printer X330 and I need to print and image (bitmap) taken from the android Camera, but I can't...I'm always get symbols in the printer.我有热敏打印机 X330,我需要打印和从 android 相机拍摄的图像(位图),但我不能......我总是在打印机中得到符号。
In the documentation said:在文档中说:
Print raster bit image打印光栅位图
I know that the bitmap need to be converted, but I can't get the correct format.我知道需要转换位图,但我无法获得正确的格式。
Someone can help me!!!有人可以帮助我!!!
Thanks in advance提前致谢
I struggled with this a little while ago and eventually got it working.不久前我为此苦苦挣扎,最终让它发挥作用。 My thermal printer is not the same one that you are using but the principle should remain the same.
我的热敏打印机与您使用的打印机不同,但原理应该保持不变。 So my printer works over USB and here is what I send to the printer for the image to be printed.
所以我的打印机通过 USB 工作,这是我发送到打印机以打印图像的内容。
byte[] rasterImage = {0x1D, 0x76, 0x30, 0x30, 0x20, 0x00, 0x00, 0x01};
File file = new File("/mnt/sdcard/1.bmp");
int size = (int) file.length();
bitmapdata = new byte[size];
try
{
BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file));
buf.read(bitmapdata, 0, bitmapdata.length);
buf.close();
} catch (FileNotFoundException e)
{
} catch (IOException e)
{
}
connection.bulkTransfer(endpoint, rasterImage, rasterImage.length, TIMEOUT);
connection.bulkTransfer(endpoint, bitmapdata, bitmapdata.length, TIMEOUT);
The rasterImage is basically the setup of the hex data needed to tell the printer than I want to print a raster bit image. rasterImage 基本上是告诉打印机我想要打印光栅位图所需的十六进制数据的设置。 Then I read the photo or image from the internal storage of the device and convert it into a byte[].
然后我从设备的内部存储中读取照片或图像并将其转换为字节 []。 Then I send the rasterImage hex data and the bitmapdata to the printer.
然后我将 rasterImage 十六进制数据和位图数据发送到打印机。
A few things to note, firstly you need to convert the image you want to print to a 1 bit depth monochrome image, you can use paint to do this (simply save the image from paint as a monochrome bitmap), you need to do this because the printer can only print a dot or no dot, it cannot print layered images etc. Second, you need to make sure that the image resolution is a multiple of 8, the reason for this is due to the xL, xH, yL and yH calculation on my printer, the one works only in bytes and so I have no way to get anything other than a multiple of 8. So my image was 256x256.需要注意的几点,首先你需要将你要打印的图像转换为1位深度的单色图像,你可以使用paint来做到这一点(只需将paint中的图像保存为单色位图),你需要这样做因为打印机只能打印一个点或不打印点,不能打印分层图像等。 其次,您需要确保图像分辨率是8的倍数,这是由于xL、xH、yL和在我的打印机上进行 yH 计算,只能以字节为单位进行计算,因此除了 8 的倍数之外,我无法获得任何其他信息。所以我的图像是 256x256。
Let me know if you have success and if you need more help let me know.如果您成功了,请告诉我,如果您需要更多帮助,请告诉我。
I did not include any USB code, but just use your bluetooth connection to send the data in a similar way.我没有包含任何 USB 代码,只是使用您的蓝牙连接以类似的方式发送数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.