how to print picture
来源:互联网 发布:java会议管理系统 编辑:程序博客网 时间:2024/06/06 02:40
private class BmpThread extends Thread {public BmpThread() {}public void run() {super.run(); try {Resources r = getResources();// 以数据流的方式读取资源InputStream is = r.openRawResource(R.drawable.test);BitmapDrawable bmpDraw = new BitmapDrawable(is);Bitmap bmp = bmpDraw.getBitmap();PrintBmp(10, bmp);} catch (Exception e) {e.printStackTrace();} finally { } }}public void PrintBmp(int startx, Bitmap bitmap) throws IOException {// byte[] start1 = { 0x0d,0x0a};byte[] start2 = { 0x1D, 0x76, 0x30, 0x30, 0x00, 0x00, 0x01, 0x00 };int width = bitmap.getWidth() + startx;int height = bitmap.getHeight();Log.e(TAG,"width: "+width+" height :"+height);if (width > 384)width = 384;int tmp = (width + 7) / 8;byte[] data = new byte[tmp];byte xL = (byte) (tmp % 256);byte xH = (byte) (tmp / 256);start2[4] = xL;start2[5] = xH;start2[6] = (byte) (height % 256);;start2[7] = (byte) (height / 256);;m_Device.sendData(start2);for (int i = 0; i < height; i++) {for (int x = 0; x < tmp; x++)data[x] = 0;for (int x = startx; x < width; x++) {int pixel = bitmap.getPixel(x - startx, i);if (Color.red(pixel) == 0 || Color.green(pixel) == 0|| Color.blue(pixel) == 0) {// 高位在左,所以使用128 右移data[x / 8] += 128 >> (x % 8);// (byte) (128 >> (y % 8));}}while ((printer_status & 0x13) != 0) {Log.e(TAG, "printer_status=" + printer_status);try {Thread.sleep(50);} catch (InterruptedException e) {}} m_Device.sendData(data); }}
阅读全文
0 0
- how to print picture
- how to print textarea
- How to Modify SAP Login Screen picture ?
- How to remove background of a picture?
- How to Print in ASP.NET 2.0
- how to print debug in Linux
- how to print function backtrack with boost
- how to print log for a developer
- [.NET] How to Create picture button in WinCE
- How to Set size for picture in datadrigview
- How to save a picture (take screenshot) from a camera
- Show how to print a table in a html page
- How To Print Concurrent Requests in PDF Format
- How to print the content of a Rich Edit Control
- .Net Windows Forms: How to Create a Custom Print Dialog
- .Net Windows Forms: How to Create a Custom Print Dialog
- .Net Windows Forms: How to Create a Custom Print Dialog
- How-to launch browser print dialog when showing printable page
- android中使用startActivityForResult回传数据(详解)
- Android 系统 log存放路径
- 【二分】基础
- JUC集合-05之 ConcurrentSkipListMap
- C++ primer 阅读笔记------------变量
- how to print picture
- 最大子串
- Hello World
- 一起从零学Kotlin-20170801
- 两个集合用单链表存储,分别求出集合的差集和并集(单链表求差集并集)
- Coursera年龄疾病问题
- linux下的etc
- 栈的基本操作
- Bootstrap基础7——按钮组button