android - zxing:创建要在 ImageView 中使用的 ean_13 条形码

标签 android zxing barcode-printing

我在搞乱 zxing library 2.2(有文档吗??)

我想做的是:

获取一个现有的EAN13字符串,将其传递给库并获取图像以在ImageView中使用(或者将其写入内部存储然后自己为imageView创建位图)

不幸的是,MatrixToImageWriter 只能在 J2SE 中使用,而不能在 android 中使用(因为 awt?),因此我不能使用它。

我找到了这篇文章 Generate barcode image in Android application

它适用于 Code128,但当我将 BarcodeFormat.CODE_128 更改为 EAN13 时,我只得到一个空图像。

有什么想法吗? 是否有其他库可以实现我想要的?

提前致谢!

最佳答案

您得到一个空图像,因为您传递的字符串不是“EAN-13”条码格式要求的格式。它应该是 13 位数字,最后一位数字应该是前 12 位数字的校验和。

您可以使用此链接获取有关 EAN-13 格式的更多信息。 http://www.barcodeisland.com/ean13.phtml

我使用了以下函数来创建字符串的校验和数字。

private int calculateChecksumDigit(String mMembershipId) {
    int total_sum=0;
    for(int i=0;i<mMembershipId.length();i++)
    {
        if(i%2!=0) {
            total_sum=total_sum+Integer.parseInt(""+mMembershipId.charAt(i))*3;
        }
        else
        {
            total_sum=total_sum+Integer.parseInt(""+mMembershipId.charAt(i));
        }
    }
    return 10-(total_sum%10);

}  

然后将其作为

传递
 BarCodeGenerator.encodeAsBitmap(mMembershipId+calculateChecksumDigit(mMembershipId), BarcodeFormat.EAN_13, widthInPixels, heightInPixels);

关于android - zxing:创建要在 ImageView 中使用的 ean_13 条形码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19384935/

相关文章:

android - 透明按钮模拟点击效果

java - android 将 json 传递给 HashMap 到 alertdialog 中显示的 llistview

image - 如何在 TSC 打印机中打印图像

php - 打印(生成)以毫米为单位的 code128 条形码(或任何图像) (php)

android - 如何在 Android 应用程序恢复互联网连接之前保持 http 请求挂起?

android网络更改广播接收器并获取网络类型

Android/ZXing 不再有效

fonts - Ean 13 字体无法从扫描仪读取

java - 在Fragment的布局中显示ZXING条码扫描仪

android - ZXing-2.1 - 缺少库