逆转start协议输出

    private static byte[] bitmap2byte(Bitmap bmp) throws Exception{
return bitmap2byte(bmp, null);
} private static byte[] bitmap2byte(Bitmap bmp, StarReverseConfig config) throws Exception{
Long s = System.currentTimeMillis();
String TAG = "Start Bitmap2byte";
int imgWidth = bmp.getWidth();
int imgHeight = bmp.getHeight(); //头 无配置
byte[] header = { 0x1b, 0x2a, 0x72, 0x42,
0x1b, 0x2a, 0x72, 0x61,
0x1b, 0x2a, 0x72, 0x41 }; //参数 配置 Set print speed : 1B1E74
//0x1b, 0x2a, 0x72, 0x6d, 0x6c, 0x24, 0x00 1b 2a 72 6d 6c n 00; Set raster left margin: n x 8
byte[] params = { };
//0x1b, 0x6c, 0x24 Set raster left margin
//0x1b, 0x1d, 0x41 n1 n2 Point absolute position
//尾 无配置
byte[] footer = { 0x1b, 0x2a, 0x72, 0x65, 0x31, 0x33, 0x00, 0x1b, 0x0c, 0x19, 0x00 };
//Storellet
//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 };
//Storellet
//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}; // 每行的字节数
int lineBytes = imgWidth / 8 + (imgWidth % 8 > 0 ? 1 : 0); //位移
int movePosition = config != null ? config.getSetLeftWidth() / 8 : 0; Log.i(TAG,"reverse lineBytes:" + lineBytes + ", imgWidth:" + imgWidth + ", imgHeight:" + imgHeight);
// 总字节长度
byte[] srcbytes = new byte[header.length + params.length + footer.length + imgHeight * (lineBytes + 3 + movePosition)]; int srclen = 0;
System.arraycopy(header, 0, srcbytes, srclen, header.length);
srclen = srclen + header.length;
System.arraycopy(params, 0, srcbytes, srclen, params.length);
srclen = srclen + params.length; byte n1byte = (byte)((lineBytes + movePosition) % 256);
byte n2byte = (byte)((lineBytes + movePosition) / 256);
byte tmp = 0;
byte p1 = 0x01, p0 = 0x00;
int xcnt = 3; // x方向上的计数 for (int y = 0; y < imgHeight; y++) {
byte[] lineBytesArray = new byte[lineBytes + 3 + movePosition];
//System.arraycopy(movePosition, 0, lineBytesArray, 0, movePosition.length);
lineBytesArray[0] = (byte)0x62;
lineBytesArray[1] = n1byte;
lineBytesArray[2] = n2byte; xcnt = 3; // x方向上的计数初始值
for (int i = 0; i < movePosition; i++) {
lineBytesArray[xcnt] = 0x00;
xcnt++;
} for (int x = 0; x < imgWidth; x++) {
if (x % 8 == 0 || x == imgWidth -1) {
if(x != 0){
lineBytesArray[xcnt] = tmp;
xcnt++;
}
tmp = 0;
}
int r = bmp.getPixel(x, y);
if (r == Color.BLACK) {
tmp += p1 * Math.pow(2, 7 - x % 8); //高位开始
} else {
tmp += p0 * Math.pow(2, 7 - x % 8);
}
}
System.arraycopy(lineBytesArray, 0, srcbytes, srclen, lineBytesArray.length);
srclen = srclen + lineBytesArray.length;
Thread.yield();
} System.arraycopy(footer, 0, srcbytes, srclen, footer.length);
Log.i(TAG,"reverse receipt is :" + srcbytes.length + ", all Time:" + (System.currentTimeMillis() - s));
return srcbytes;
}

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. 3d世界是怎样呈现到屏幕上的

    要把一个3d物体呈现在屏幕上,要经过一系列的步骤. 描述3d世界 把3d世界绘制在二维屏幕上 如何描述一个3D世界? 数学家早就给出了3D世界的模型,我们日常最熟悉的3维坐标系就是一个欧几里得空间(线 ...

  2. tortoiseGIT保存用户名密码

    虽然GIT可以使用SSH来免去输入用户名密码的麻烦,但是更多的人我相信还是比较喜欢使用tortoiseGIT. 使用HTTP模式的代码库可以通过保存用户名密码的方式来免去重复输入的麻烦. 首先安装gi ...

  3. iOS使用shell脚本注入混淆内容

    背景 公司需要做一系列的壳版本,壳版本如果内容雷同提交到App Store会有被拒绝的风险,其中有一种解决方案是在壳版本中注入混淆的代码,防止被苹果检测到内容太过雷同而导致审核被拒绝,本文是针对这个场 ...

  4. Microsoft SQL Server Express各版本对比

    Microsoft® SQL Server® 2016 Express 支持的操作系统 Windows 10 , Windows 8, Windows Server 2012, Windows Ser ...

  5. 6-8 Percolate Up and Down(20 分)

    Write the routines to do a "percolate up" and a "percolate down" in a binary min ...

  6. scrapy多线程文件下载

    在爬取数据时有时候有些文件数据需要爬取下载下来使用多线程下载可以让程序跑的更快点. scrapy中有个扩展可以使用扩展模块来实现下载. 在自己的spider中加入 custom_settings cl ...

  7. 如何检测MySQL中建立的索引是否生效

    使用方法,在select语句前加上explain就可以了: EXPLAIN SELECT surname,first_name form a,b WHERE a.id=b.id EXPLAIN列的解释 ...

  8. TypeScript学习笔记(八) - 声明文件

    本篇将介绍TypeScript的声明文件,并简单演示一下如何编写和使用声明文件.本篇也是这个系列的最后一篇. 一.声明文件简介 TypeScript作为JavaScript的超集,在开发过程中不可避免 ...

  9. 使用nomad && consul && fabio 创建简单的微服务系统

    具体每个组件的功能就不详细说明了 nomad 一个调度工具,consul 一个服务发现,健康检查多数据中心支持的工具 fabio 一个基于consul的负载均衡&&动态路由工具,对于集 ...

  10. postgres 使用存储过程批量插入数据

    參考资料(pl/pgsql 官方文档): http://www.postgresql.org/docs/9.3/static/plpgsql.html create or replace functi ...