图片转打印指令(cpcl和zpl)

    public static String convertImageToHex(Bitmap orginalImage){
        StringBuffer sb = new StringBuffer();
        int height = orginalImage.getHeight();
        int width = orginalImage.getWidth();
        int rgb, red, green, blue, index = 0;
        char auxBinaryChar[] = {'0', '0', '0', '0', '0', '0', '0', '0'};
        for (int h = 0; h < height; h++) {
            for (int w = 0; w < width; w++) {
                rgb = orginalImage.getPixel(w,h);
                red = (rgb >> 16) & 0x000000FF;
                green = (rgb >> 8) & 0x000000FF;
                blue = (rgb) & 0x000000FF;
                char auxChar = '1';
                int totalColor = red + green + blue;
                if (totalColor > 450) {
                    auxChar = '0';
                }
                auxBinaryChar[index] = auxChar;
                index++;
                if (index == 8 || w == (width - 1)) {
                    int decimal = Integer.parseInt(new String(auxBinaryChar), 2);
                    String hex =  decimal > 15 ? Integer.toString(decimal, 16).toUpperCase() : "0" + Integer.toString(decimal, 16).toUpperCase();
                    sb.append(hex);
                    auxBinaryChar = new char[]{'0', '0', '0', '0', '0', '0', '0', '0'};
                    index = 0;
                }
            }
        }
        return  sb.toString();
    }
cpcl:"EG " +  width + " " + height * 8 + " 0" + " 0" + " " + imgHex
zpl:"^GFA," + width * height * 8 + "," + width * height * 8 + "," + width + "," + imgHex
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值