簡體   English   中英

Android上的Barcode4J(缺少BufferedImage支持)

[英]Barcode4J on Android ( missing BufferedImage support )

我一直在嘗試在Android上使用Barcode4J,但似乎無法獲得BufferedImage類,而且我不確定如何用Android.graphic。*中的任何內容替換此類,但似乎沒有類似之處。 此外,出於明顯的原因,Barcode4J將不接受BufferedImage對象以外的任何對象。 我該用什么代替?或者有一個更適合Android的條形碼生成器庫?

我嘗試過Barcode4Android,這確實沒有任何意義,因為他們在GIT上給出的示例使用了java.awt.image.BufferedReader包中的BufferedImage也>。<。 所以我回到了第一步。

我實際上只需要QR生成功能。

我的問題。 1.是否有Android版Barcode4J的替代品。 2.還是可以解決我的問題?

這是我嘗試使用的Java教程之一

public class HelloExample1 {

public static void main(String[] args) throws Exception{
    //Create the barcode bean
    Code39Bean bean = new Code39Bean();

    final int dpi = 150;

    //Configure the barcode generator
    bean.setModuleWidth(UnitConv.in2mm(1.0f / dpi)); //makes the narrow bar, width exactly one pixel
    bean.setWideFactor(3);
    bean.doQuietZone(false);

    //Open output file
    File outputFile = new File("resources"+"/"+"images"+"/"+"out.png");
    OutputStream out = new FileOutputStream(outputFile);

    try {

        //Set up the canvas provider for monochrome PNG output
        BitmapCanvasProvider canvas = new BitmapCanvasProvider(
            out, "image/x-png", dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0);

        //Generate the barcode
        bean.generateBarcode(canvas, "Hello World");

        //Signal end of generation
        canvas.finish();
    } finally {
        out.close();
    }
}
}

嘗試Zxing ,它是一個代碼生成器和閱讀器,可在Android中輕松使用。 希望能幫助到你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM