Here is what i have tried.
I have implemented Zbar Scanner in android application in which I can scan barocde and get result.
I have implemented this in my android project. now I want to implement scanner which scans images(of course Bar code images) from gallery. I know this can be possible anyhow. check this link. It has barcode image scanning.
I have tried to search it out but failed. Please Help me out.
Scan with the Gallery app Open the Gallery app on Huawei phone, tap on the image to reveal the bottom menu. Select “More” then wait for a second until you see the 'Scan QR code in image' option at the bottom of the menu. Tap on the option to allow the phone to scan the QR code from the image.
The simple answer is yes - if the barcode scanner that you have has what is known as a 2D (two dimensional) imager as its scan engine. Barcode scanners come with two different types of scan engines.
This is possible now with the new Barcode Scanning Apis available from Google Play Services 7.8 version. It has method to detect barcode passed as a bitmap. Get path of image from gallery and convert it to bitmap and pass it like below:
Frame frame = new Frame.Builder().setBitmap(bitmap).build();
BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context)
.build();
if(barcode.isOperational()){
SparseArray<Barcode> sparseArray = barcodeDetector.detect(frame);
if(sparseArray != null && sparseArray.size() > 0){
for (int i = 0; i < sparseArray.size(); i++){
Log.d(LOG_TAG, "Value: " + sparseArray.valueAt(i).rawValue + "----" + sparseArray.valueAt(i).displayValue);
Toast.makeText(LOG_TAG, sparseArray.valueAt(i).rawValue, Toast.LENGTH_SHORT).show();
}
}else {
Log.e(LOG_TAG,"SparseArray null or empty");
}
}else{
Log.e(LOG_TAG, "Detector dependencies are not yet downloaded");
}
In your build.gradle file, include the following under dependencies section: compile 'com.google.android.gms:play-services:7.8.+'
Following Manifest permissions are must:
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Meta data for google play services:
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
Meta data for first time install/run time dependencies to be downloaded for getting barcode detector operational.
<meta-data
android:name="com.google.android.gms.vision.DEPENDENCIES"
android:value="barcode" />
For detailed usage of this api, Refer Github Sample, follow Code Lab, Documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With