I have an app that receives receipt photos and I'd like to use Zxing in order to read this bitmaps and extract the QR code and Bar code information. Is that possible? If yes, can you please share the code for Android?
3 Answers
If you do not want to stick to Zxing, you can go for Barcode Scanning Apis available from Google Play Service 7.8 version. This has the capability to read various kinds of Barcode. It can take either image as bitmap or scan a barcode live. Assuming you have got an image from gallery and converted it to bitmap. Please find below code for sending a barcode image to be scanned using this library.
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.+'
and add the following Manifest permissions:
<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.

- 827
- 9
- 16

- 1,202
- 13
- 27
Its very simple, you need to call startActivityforResult, similar to calling another activity ..
In your action when scanning is invoked you need call following:
public InvokeScan()
{
mAppPAckage="com.google.zxing.client.android.SCAN"
Intent intentScan = new Intent(mAppPackage);
intentScan.addCategory(Intent.CATEGORY_DEFAULT);
// set the desired barcode types
intentScan.putExtra("SCAN_FORMATS", stringDesiredBarcodeFormats);
final PackageManager packageManager = activity.getPackageManager();
List<ResolveInfo> list = packageManager.queryIntentActivities(intentScan,
PackageManager.MATCH_DEFAULT_ONLY);
activity.startActivityForResult(intentScan,REQUEST_CODE);
onActivityResult , you need to capture the result
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (resultCode == Activity.RESULT_OK)
{
String desiredBarCodeFormat = BarCodeActivity.sDesiredBarcodeFormatValue;*/
String contents = intent.getStringExtra(activityBundleName);
String formatName = intent.getStringExtra(desiredBarCodeFormat);
//do whatever you want from contents.
}
}
Contents would be the barcode number that you need.

- 503
- 10
- 25

- 5,541
- 1
- 20
- 17
-
Hi Ashish Rawat, thank you for awnsering the question, but I'm looking for a way to send a pircture that is already in the phone to the Zxing in order to get the bar code. Do you know how to achieve this? Thank you. – Carlos Oct 17 '15 at 18:44
There are various forks of ZXing that you can use.
For example: https://zxingnet.codeplex.com/
// create a barcode reader instance
IBarcodeReader reader = new BarcodeReader();
// load a bitmap
var barcodeBitmap = (Bitmap)Bitmap.LoadFrom("C:\\sample-barcode-image.png");
// detect and decode the barcode inside the bitmap
var result = reader.Decode(barcodeBitmap);
// do something with the result
if (result != null)
{
txtDecoderType.Text = result.BarcodeFormat.ToString();
txtDecoderContent.Text = result.Text;
}

- 8,589
- 1
- 28
- 34

- 5,541
- 1
- 20
- 17
-
2The example provided is a .NET version of zxing and won't work in Android. OP hasn't mentioned xamarin so I don't think this is relevant – redspidermkv Nov 24 '15 at 16:30