简体   繁体   English

如何在Android中生成24位位图

[英]How to generate a 24bit Bitmap in android

I am working on android app that needs to generate a QRCode, and I successfully done with this. 我正在开发需要生成QRCode的android应用,并且我成功完成了此操作。

My problem is on the printing side. 我的问题是在打印方面。 I used a Mobiprint 3 device which has a built-in Thermal Printer. 我使用了带有内置热敏打印机的Mobiprint 3设备。 But my problem is the device printer only support a 24bit Bitmap. 但是我的问题是设备打印机仅支持24位位图。

My question is, is there a way to create a 24bit Bitmap in android? 我的问题是,有没有一种方法可以在Android中创建24位位图? since it only support a 32bit. 因为它仅支持32bit。 I googled it in a week but no one solved my problem. 我在一周内用谷歌搜索,但没人能解决我的问题。

Thank you in advance. 先感谢您。

BTW. BTW。

This is my code 这是我的代码

//method for generating a QRCode Bitmap //生成QRCode位图的方法

    try {
        bitmap = qrGenerator.generateQRCode(duCode);
        int width, height;
        height = bitmap.getHeight();
        width = bitmap.getWidth();

        bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(bmpGrayscale);
        Paint paint = new Paint();
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
        paint.setColorFilter(f);
        c.drawBitmap(bitmap, 0, 0, paint);

    } catch (WriterException e) {
        e.printStackTrace();
    }
}

and this is when calling the Bitmap for printing. 这是在调用位图进行打印时。

print.printBitmap(getBitmap());

this codes only prints a pure square black. 此代码仅打印纯正方形黑色。

PS: print.printBitmap() is from the Mobiprint API. PS:print.printBitmap()来自Mobiprint API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM