Java Question Update zxing lib to make it Create 2D Code

chjk

Member
Licensed User
Longtime User
I add the following code in b4aZXingLib.java
B4X:
/**
    * Create QR Code
    * @param str
    * @author chjk
    * @return Bitmap
    * @throws WriterException
    */ 
    public Bitmap Create2DCode(String str) throws WriterException, UnsupportedEncodingException {
       
        BitMatrix matrix = new MultiFormatWriter().encode(new String(str.getBytes("GBK"),"ISO-8859-1"),BarcodeFormat.QR_CODE, 300, 300);
       
        int width = matrix.getWidth();
        int height = matrix.getHeight();
        int[] pixels = new int[width * height];
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                if(matrix.get(x, y)){
                    pixels[y * width + x] = 0xff000000;
                }
               
            }
        }   
        //int[] colors={R.color.white};
        Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
       
        bmp.setPixels(pixels, 0, width, 0, 0, width, height);
        return bmp;
    }
}
Create zxinglib is normal, but the reference problem. Zxing ver 2.3
 

Attachments

  • libError.png
    libError.png
    8 KB · Views: 317
  • b4aZxing2.3Libsrc.zip
    475.8 KB · Views: 340

juanomoran

Member
Licensed User
Longtime User
Could you solve the problem? I'm very interested in creating custom qr codes from my app.
 

juanomoran

Member
Licensed User
Longtime User
Thank you Nelson, I will take a look at the post you suggest.

Anyway just for the record, I tried to compile the library provided by chjk using the SLC. Everything works fine with the compiler (except for some warnings shown while creating XML file: "No ShortName annotation found for class: FinderPattern" - this is an example, it happens for many, if not all, classes).

After "succesfull" creation, when I refresh the Aditional libraries tab and try to use it, it still shows the same exact problem as the one found by chjk.


Thanks again

Juan
 

Johan Schoeman

Expert
Licensed User
Longtime User
You should exclude all the classes that are not supposed to be exposed by the library.
Use the b4aignore field for this. Change xxx to com.
Thanks Erel. It is working!! I guess that with this you will be making a lot of people to be very happy teddy bears indeed.:)
 

Johan Schoeman

Expert
Licensed User
Longtime User
You should exclude all the classes that are not supposed to be exposed by the library.
Use the b4aignore field for this. Change xxx to com.
Erel, one last question on is. Should a /res folder resides in the root directory (along with the /src and /libs folders when you compile a library or in the /additional folder? Is it necessary to add the /res folder during compilation or should it just be added to correct folder of the B4A project?
 
Top