简体   繁体   中英

Barcode4J on Android ( missing BufferedImage support )

I have been trying to use Barcode4J on Android but I can not seem to get BufferedImage class and I am not sure how I am suppose to replace this class with anything from Android.graphic.* which does not seem to have something similar. Also the Barcode4J will not accept anything other then BufferedImage object for obvious reasons. What could I use instead or is there a Barcode generator Lib better suited for Android?

I have tried Barcode4Android which really made no sense since the Example they gave on GIT used BufferedImage from the java.awt.image.BufferedReader package also >.< . So I was back at step 1.

I actually just need the QR generating function.

My Questions. 1. Is there an Alternative to Barcode4J for Android. 2. OR is there a work around for my problem ?

Here is one of the Java tutorials I tried to use

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();
    }
}
}

Try Zxing , its a code generator and reader, easy to use in Android. Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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