逆转start协议输出

  1. private static byte[] bitmap2byte(Bitmap bmp) throws Exception{
  2. return bitmap2byte(bmp, null);
  3. }
  4.  
  5. private static byte[] bitmap2byte(Bitmap bmp, StarReverseConfig config) throws Exception{
  6. Long s = System.currentTimeMillis();
  7. String TAG = "Start Bitmap2byte";
  8. int imgWidth = bmp.getWidth();
  9. int imgHeight = bmp.getHeight();
  10.  
  11. //头 无配置
  12. byte[] header = { 0x1b, 0x2a, 0x72, 0x42,
  13. 0x1b, 0x2a, 0x72, 0x61,
  14. 0x1b, 0x2a, 0x72, 0x41 };
  15.  
  16. //参数 配置 Set print speed : 1B1E74
  17. //0x1b, 0x2a, 0x72, 0x6d, 0x6c, 0x24, 0x00 1b 2a 72 6d 6c n 00; Set raster left margin: n x 8
  18. byte[] params = { };
  19. //0x1b, 0x6c, 0x24 Set raster left margin
  20. //0x1b, 0x1d, 0x41 n1 n2 Point absolute position
  21. //尾 无配置
  22. byte[] footer = { 0x1b, 0x2a, 0x72, 0x65, 0x31, 0x33, 0x00, 0x1b, 0x0c, 0x19, 0x00 };
  23. //Storellet
  24. //byte[] header = {0x1b, 0x2a, 0x72, 0x42, 0x1b, 0x1d, 0x03, 0x04, 0x00, 0x00, 0x17, 0x00, 0x1b, 0x1e, 0x45, 0x00, 0x1b, 0x06, 0x01, 0x00, 0x1b, 0x06, 0x01, 0x00, 0x1b, 0x1d, 0x03, 0x03, 0x00, 0x00, 0x1b, 0x2a, 0x72, 0x41, 0x1b, 0x2a, 0x72, 0x50, 0x30, 0x00, 0x1b, 0x2a, 0x72, 0x45, 0x31, 0x00, 0x1b, 0x2a, 0x72, 0x59, 0x30, 0x30, 0x33, 0x00 };
  25. //Storellet
  26. //byte[] footer = { 0x1b, 0x2a, 0x72, 0x59, 0x30, 0x30, 0x31, 0x00, 0x1b, 0x2a, 0x72, 0x65, 0x31, 0x33, 0x00, 0x1b, 0x0c, 0x19, 0x1b, 0x2a, 0x72, 0x46, 0x31, 0x33, 0x00, 0x1b, 0x0c, 0x00, 0x1b, 0x2a, 0x72, 0x42, 0x1b, 0x2a, 0x72, 0x42, 0x1b, 0x1d, 0x03, 0x04, 0x00, 0x00, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  27.  
  28. // 每行的字节数
  29. int lineBytes = imgWidth / 8 + (imgWidth % 8 > 0 ? 1 : 0);
  30.  
  31. //位移
  32. int movePosition = config != null ? config.getSetLeftWidth() / 8 : 0;
  33.  
  34. Log.i(TAG,"reverse lineBytes:" + lineBytes + ", imgWidth:" + imgWidth + ", imgHeight:" + imgHeight);
  35. // 总字节长度
  36. byte[] srcbytes = new byte[header.length + params.length + footer.length + imgHeight * (lineBytes + 3 + movePosition)];
  37.  
  38. int srclen = 0;
  39. System.arraycopy(header, 0, srcbytes, srclen, header.length);
  40. srclen = srclen + header.length;
  41. System.arraycopy(params, 0, srcbytes, srclen, params.length);
  42. srclen = srclen + params.length;
  43.  
  44. byte n1byte = (byte)((lineBytes + movePosition) % 256);
  45. byte n2byte = (byte)((lineBytes + movePosition) / 256);
  46. byte tmp = 0;
  47. byte p1 = 0x01, p0 = 0x00;
  48. int xcnt = 3; // x方向上的计数
  49.  
  50. for (int y = 0; y < imgHeight; y++) {
  51. byte[] lineBytesArray = new byte[lineBytes + 3 + movePosition];
  52. //System.arraycopy(movePosition, 0, lineBytesArray, 0, movePosition.length);
  53. lineBytesArray[0] = (byte)0x62;
  54. lineBytesArray[1] = n1byte;
  55. lineBytesArray[2] = n2byte;
  56.  
  57. xcnt = 3; // x方向上的计数初始值
  58. for (int i = 0; i < movePosition; i++) {
  59. lineBytesArray[xcnt] = 0x00;
  60. xcnt++;
  61. }
  62.  
  63. for (int x = 0; x < imgWidth; x++) {
  64. if (x % 8 == 0 || x == imgWidth -1) {
  65. if(x != 0){
  66. lineBytesArray[xcnt] = tmp;
  67. xcnt++;
  68. }
  69. tmp = 0;
  70. }
  71. int r = bmp.getPixel(x, y);
  72. if (r == Color.BLACK) {
  73. tmp += p1 * Math.pow(2, 7 - x % 8); //高位开始
  74. } else {
  75. tmp += p0 * Math.pow(2, 7 - x % 8);
  76. }
  77. }
  78. System.arraycopy(lineBytesArray, 0, srcbytes, srclen, lineBytesArray.length);
  79. srclen = srclen + lineBytesArray.length;
  80. Thread.yield();
  81. }
  82.  
  83. System.arraycopy(footer, 0, srcbytes, srclen, footer.length);
  84. Log.i(TAG,"reverse receipt is :" + srcbytes.length + ", all Time:" + (System.currentTimeMillis() - s));
  85. return srcbytes;
  86. }

Android bitmap转byte的更多相关文章

  1. Android Bitmap Drawable byte[] InputStream 相互转换方法

    用android处理图片的时候,由于得到的资源不一样,所以经常要在各种格式中相互转化,以下介绍了 Bitmap Drawable byte[] InputStream 之间的转换方法: import ...

  2. Android中Bitmap, Drawable, Byte,ID之间的转化

    Android中Bitmap, Drawable, Byte,ID之间的转化 1.  Bitmap 转化为 byte ByteArrayOutputStream out = new ByteArray ...

  3. Android Bitmap与DrawAble与byte[]与InputStream之间的转换工具类【转】

    package com.soai.imdemo; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; ...

  4. Android Drawable、Bitmap、byte[]之间的转换

    转自http://blog.csdn.net/june5253/article/details/7826597 1.Bitmap-->Drawable Bitmap drawable2Bitma ...

  5. android开发之Bitmap 、byte[] 、 Drawable之间的相互转换

    一.相关概念 1.Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable) ...

  6. [翻译]开发文档:android Bitmap的高效使用

    内容概述 本文内容来自开发文档"Traning > Displaying Bitmaps Efficiently",包括大尺寸Bitmap的高效加载,图片的异步加载和数据缓存 ...

  7. Android Bitmap 和 ByteArray的互相转换

    Android Bitmap 和 ByteArray的互相转换 移动平台图像处理,需要将图像传给native处理,如何传递?将bitmap转换成一个 byte[] 方便传递也方便cpp代码直接处理图像 ...

  8. Android-Drawable、Bitmap、byte[]、资源文件相互转换

    我们在Android的开发中,经常可以遇到图片的处理,当中,有很多是 Bitmap.Drawable.byte[]和资源文件它们直接相互转换. 今天就此总结一下: 1.资源文件转为Drawable 2 ...

  9. android Bitmap类方法属性 详细说明

    (转:http://blog.csdn.net/ymangu666/article/details/37729109) 1.  BitMap类public void recycle()——回收位图占用 ...

随机推荐

  1. const关键字对C++成员函数的修饰

    const对C++成员函数的修饰分为三种:1. 修饰参数:2. 修饰返回值:3. 修饰this指针.简述一下知识点如下,以后找功夫再完善. 1. 对函数参数的修饰. 1)const只能用来修饰输入参数 ...

  2. zookeeper的安装和部署

    参考: https://testerhome.com/topics/11361 http://blog.csdn.net/lihao21/article/details/51778255 https: ...

  3. zz VS2010配色方案

    http://studiostyles.info 这个网站专门为vs 2005, vs 2008, vs2010提供配色方案下载. 网站首页罗列出大量的配色方案,都附有缩略图以及rated(评估),d ...

  4. [批处理]简易命令行RAR

    这个BAT是为了病毒满满的信管实验室而专门定制的,在这机房上了两年,跟病毒也玩了两年了,也都脸熟的不行不行的了,来来回回就那几个病毒不是autorun.inf就是Desktop__.ini要么就是ga ...

  5. Hibernate结合JPA编写通用泛型多条件查询

    项目中使用Hibernate和JPA对数据库对象进行实例化,但是生成的方法不支持多条件查询.而如果针对每一个数据库对象进行多条件查询编码,则会变得很麻烦,而且一旦以后发生表结构发生变化,这些方法可能还 ...

  6. ajax向后台请求数据,后台接收到数据并进行了处理,但前台就是调用error方法

    如果你的前台页面书写正确的情况下,并且运行情况和本文题目类似,那不妨试试这个: 在ajax方法中加上:async:false,让ajax同步执行. 因为ajax默认是异步的,至于为什么会不执行succ ...

  7. 捕捉过滤器(CaptureFilters)和显示过滤器(DisplayFilters)--Wireshark

    Wireshark的基本使用——过滤器 前言 网络上关于Wireshark的教程已有不少,博主就简单介绍一下Wireshark分析数据包时最重要的技巧之一的过滤器..一次性嗅探到的数据包有很多,想要高 ...

  8. 整理了一下 ThinkPHP 历史

    整理了一下 ThinkPHP 历史 ThinkPHP 一款国内最流行的 PHP 开源框架.

  9. centos7 安装配置rsyslog + LogAnalyzer + mysql

    https://www.cnblogs.com/mchina/p/linux-centos-rsyslog-loganalyzer-mysql-log-server.html 安装LNMP 一键安装包 ...

  10. Web验证方式(3)--OAuth 2.0协议

    介绍 OAuth协议是用来解决第三方应用程序访问Http Service的时候的认证问题.举个例子:某视频网站支持用户通过微信登陆,然后获取用户在微信上的图像信息. 在这个场景里 微信充当的就是Htt ...