Generate Barcode Image in Android Application

Generate barcode image in Android application

Thanks for your answers guys... In the meantime I found solution so here is what I used: http://www.onbarcode.com/products/android_barcode/barcodes/ean13.html
It's a library that worked fine for me so if anyone has the same issue I suggest using it.

Thanks again!

Android ZXing Get Barcode Image

Take the views cache and save it in bitmap something like this

View myBarCodeView = view.getRootView()
//Else this might return null
myBarCodeView.setDrawingCacheEnabled(true)
//Save it in bitmap
Bitmap mBitmap = myBarCodeView.getDrawingCache()

OR
draw your own barcode or QR CODE

//Change the writers as per your need
private void generateQRCode(String data) {
com.google.zxing.Writer writer = new QRCodeWriter();
String finaldata =Uri.encode(data, "ISO-8859-1");
try {
BitMatrix bm = writer.encode(finaldata,BarcodeFormat.QR_CODE, 350, 350);
mBitmap = Bitmap.createBitmap(350, 350, Config.ARGB_8888);
for (int i = 0; i < 350; i++) {
for (int j = 0; j < 350; j++) {
mBitmap.setPixel(i, j, bm.get(i, j) ? Color.BLACK: Color.WHITE);
}
}
} catch (WriterException e) {
e.printStackTrace();
}
if (mBitmap != null) {
mImageView.setImageBitmap(mBitmap);
}
}
public void generateBarCode(String data){
com.google.zxing.Writer c9 = new Code128Writer();
try {
BitMatrix bm = c9.encode(data,BarcodeFormat.CODE_128,350, 350);
mBitmap = Bitmap.createBitmap(350, 350, Config.ARGB_8888);

for (int i = 0; i < 350; i++) {
for (int j = 0; j < 350; j++) {

mBitmap.setPixel(i, j, bm.get(i, j) ? Color.BLACK : Color.WHITE);
}
}
} catch (WriterException e) {
e.printStackTrace();
}
if (mBitmap != null) {
mImageView.setImageBitmap(mBitmap);
}
}

Once you get the bitmap image just save it

//create a file to write bitmap data
File f = new File(FilePath, FileName+".png");
f.createNewFile();

//Convert bitmap to byte array
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ImageBitmap.compress(CompressFormat.PNG, 0, bos);
byte[] bytearray = bos.toByteArray();

//Write bytes in file
FileOutputStream fos = new FileOutputStream(f);
fos.write(bytearray);
fos.flush();
fos.close();

You can also check a small library from github that i had created to create Barcode or QR Code

GZxingEncoder   Encoder = GZxingEncoder.getInstance();
Encoder.initalize(this);
//To generate bar code use this
Bitmap bitmap = Encoder.generateBarCode_general("some text")

How to generate a QR Code for an Android application?

Have you looked into ZXING?
I've been using it successfully to create barcodes.
You can see a full working example in the bitcoin application src

// this is a small sample use of the QRCodeEncoder class from zxing
try {
// generate a 150x150 QR code
Bitmap bm = encodeAsBitmap(barcode_content, BarcodeFormat.QR_CODE, 150, 150);

if(bm != null) {
image_view.setImageBitmap(bm);
}
} catch (WriterException e) { //eek }

Android: create barcode image and display in imageView

The whole java.awt.* framework isn't part of the Android SDK,
including BufferedImage, and hence not supported by the emulator or
physical devices. Android has its own implementation for loading and
rendering graphics.

Referance here

As far as solution to problem refer here.. It uses Bitmap class to aid in creating Barcode..

Hope this helps...

Android Generate QR code and Barcode using Zxing

You are using QRCodeWriter. If you want to write another type of code, use another Writer.

Check this MultiFormatWriter - it can write any type of bar or find specific writers here in subfolders (this is from zxing library)

Create/Generate Barcode using Zxing on Android

Scanning via Intent should be all you need: https://github.com/zxing/zxing/wiki/Scanning-Via-Intent



Related Topics



Leave a reply



Submit