通过蓝牙打印机打印字符串打印图像 [英] print image via bluetooth printer prints string

查看:1084
本文介绍了通过蓝牙打印机打印字符串打印图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在通过蓝牙打印机打印图像在努力。当我测试它
文本打印它完美。但是,当涉及到图像时,只打印字符串中的字符。
我已经转换的布局成位图。并保存它变成SD卡。我需要的位图转换成
一些支持的打印机。我用我的应用程序ZEBRA EZ320打印机。
我用下面的code将布局转换成位图

 查看rootView = findViewById(android.R.id.content).getRootView();
rootView.setDrawingCacheEnabled(真);
返回rootView.getDrawingCache();


解决方案

我找到了解决我的问题。

 位图localBitmap = BitmapFactory.de codeResource(getResources(),图像);
BluetoothConnection的myconn =新BluetoothConnection(MACADDR);
ZebraPrinter myPrinter =新ZebraPrinterCpcl(的myconn);
myConn.open();
新ZebraPrinterLegacyDelegator(myPrinter).getGraphicsUtil()printImage(localBitmap,0,0,-1,-1,假)。
//减少额外的空间
myConn.write(!公用事业\\ r \\ n在-MILLIMETERS \\ r \\ nSETFF 10 2 \\ r \\ n打印\\ r \\ n.getBytes());
myConn.close();

I have been working in printing an image via bluetooth printer. When I test it for text printing it works perfectly. But when it comes to image, prints only string characters. I have converted the layout into bitmap. And saved it into sd card. Do I need to convert the bitmap into something that supports for printer. Am using "ZEBRA EZ320" printer for my application. I have used the following code to convert the layout into bitmap,

View rootView = findViewById(android.R.id.content).getRootView();
rootView.setDrawingCacheEnabled(true);
return rootView.getDrawingCache();

解决方案

I found solution to my problem.

Bitmap localBitmap=BitmapFactory.decodeResource(getResources(), image);
BluetoothConnection  myConn = new BluetoothConnection(macaddr);
ZebraPrinter myPrinter = new ZebraPrinterCpcl(myConn);
myConn.open();
new ZebraPrinterLegacyDelegator(myPrinter).getGraphicsUtil().printImage(localBitmap, 0, 0, -1, -1,       false);
// to reduce extra space 
myConn.write("! UTILITIES\r\nIN-MILLIMETERS\r\nSETFF 10 2\r\nPRINT\r\n".getBytes());
myConn.close();

这篇关于通过蓝牙打印机打印字符串打印图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆