我必须在热蓝牙打印机上打印一些数据,我正在这样做:
String message="abcdef any message 12345";
byte[] send;
send = message.getBytes();
mService.write(send);
Run Code Online (Sandbox Code Playgroud)
它适用于文本,但不适用于图像.我想我需要获取byte[]图像数据.我尝试以这种方式获取图像的数据:
Bitmap bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.qrcode);
ByteArrayOutputStream stream=new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream);
byte[] image=stream.toByteArray();
Run Code Online (Sandbox Code Playgroud)
不幸的是,打印机会打印出许多奇怪的字符(大约50厘米的纸张).我不知道如何打印图像.
我想尝试获取位图的像素,然后将其转换为a byte[]并发送它,但我不知道该怎么做.
谢谢
更新:
经过这么多时间,我这样做:我有一个名为print_image(String file)的方法,它获取我想要打印的图像的路径:
private void print_image(String file) {
File fl = new File(file);
if (fl.exists()) {
Bitmap bmp = BitmapFactory.decodeFile(file);
convertBitmap(bmp);
mService.write(PrinterCommands.SET_LINE_SPACING_24);
int offset = 0;
while (offset < bmp.getHeight()) {
mService.write(PrinterCommands.SELECT_BIT_IMAGE_MODE);
for (int x = 0; x < bmp.getWidth(); ++x) {
for (int k = 0; k < …Run Code Online (Sandbox Code Playgroud) 我们需要一台可以通过蓝牙或wifi连接到Android手机的便携式打印机(手持设备,这很重要).
我下载了一个名为PrintShare的实用程序,它允许用户通过无线或参与PrintShare网络的计算机将打印机,联系人列表,日历等内容打印到打印机上.
我想让我的Android应用创建一个文本文件,然后将该文本文件发送到与PrintShare共享的打印机.
是否有用于在Android上打印的API?
谢谢迈克
我有两个不同的蓝牙打印机.Bixolon SPP-R200和Fujitsu FTP-628WSL110.我可以分别连接到每个(使用三星Galaxy SII)打印,断开连接并重新连接就好了.但是,如果我关闭Bixolon并尝试与Fujitsu配对(之前未配对,Bixolon仍然配对),那么当尝试连接到创建的套接字时它会失败.相反的方式.
这是错误消息:
07-02 13:00:11.040: E/MyApp.BluetoothConnection(9380): Failed to connect to rfcomm socket.
07-02 13:00:11.040: E/MyApp.BluetoothConnection(9380): java.io.IOException: Service discovery failed
07-02 13:00:11.040: E/MyApp.BluetoothConnection(9380): at android.bluetooth.BluetoothSocket$SdpHelper.doSdp(BluetoothSocket.java:406)
07-02 13:00:11.040: E/MyApp.BluetoothConnection(9380): at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:217)
07-02 13:00:11.040: E/MyApp.BluetoothConnection(9380): at MyApp.BluetoothConnection.connect(BluetoothConnection.java:171)
07-02 13:00:11.040: E/MyApp.BluetoothConnection(9380): at MyApp.AbstractBluetoothPrinter.connect(AbstractBluetoothPrinter.java:34)
Run Code Online (Sandbox Code Playgroud)
这是代码,它使连接尝试,在解释的情况下失败的行是btSocket.connect(); - 例外见上文:
/** Is set in connect() */
private BluetoothSocket btSocket = null;
/** Is set prior to connect() */
private BluetoothSocket btDevice;
public boolean connect(){
try {
btSocket = btDevice.createRfcommSocketToServiceRecord("00001101-0000-1000-8000-00805F9B34FB");
if (btDevice.getName().startsWith("FTP")) {
//Special treatment for the …Run Code Online (Sandbox Code Playgroud)