繁体   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