Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

read qr code from image java

// Imports
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.google.zxing.BinaryBitmap;
import com.google.zxing.ChecksumException;
import com.google.zxing.FormatException;
import com.google.zxing.LuminanceSource;
import com.google.zxing.NotFoundException;
import com.google.zxing.RGBLuminanceSource;
import com.google.zxing.Reader;
import com.google.zxing.Result;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.QRCodeReader;

// Interesting method
public static String decodeQRImage(String path) {
    Bitmap bMap = BitmapFactory.decodeFile(path);
    String decoded = null;

    int[] intArray = new int[bMap.getWidth() * bMap.getHeight()];
    bMap.getPixels(intArray, 0, bMap.getWidth(), 0, 0, bMap.getWidth(),
            bMap.getHeight());
    LuminanceSource source = new RGBLuminanceSource(bMap.getWidth(),
            bMap.getHeight(), intArray);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

    Reader reader = new QRCodeReader();
    try {
        Result result = reader.decode(bitmap);
        decoded = result.getText();
    } catch (NotFoundException e) {
        e.printStackTrace();
    } catch (ChecksumException e) {
        e.printStackTrace();
    } catch (FormatException e) {
        e.printStackTrace();
    }
    return decoded;
}
Comment

PREVIOUS NEXT
Code Example
Java :: How to read and write XML files 
Java :: set matrix zeros programming creek 
Java :: convert class to java command line 
Java :: latest android sdk version 
Java :: initialize hashmap java 
Java :: java 8 stream option 
Java :: arraylist 
Java :: spring valid request body custom message 
Java :: eliminar el primer caracter de un string java 
Java :: prime numbers program in java 
Java :: java stream sort 
Java :: android navigation drawer open activity 
Java :: deserialize list jackson 
Java :: java implement interface 
Java :: Java String equal String 
Java :: java checked exception 
Java :: how to convert errorBody to pojo in retrofit 
Java :: java Convert a string IPv4 IP address to the equivalent long numeric value. 
Java :: Android Number Picker format JAVA 
Java :: array reverse in java 
Java :: erstelle hashmap java 
Java :: How to find the maximum occurring character in a given String? using hashmap java 
Java :: setimageuri crash 
Java :: generate random number using math.random in java 
Java :: comparestring java 
Java :: java array merge 
Java :: String Reverse Program in Java. 
Java :: array de meses java 
Java :: random int between two values 
Java :: width and height of screen java 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =