我有一個接收收據照片的應用程序,我想使用Zxing來閱讀此位圖並提取QR碼和條碼信息。那可能嗎?如果是的話,你能分享一下Android的代碼嗎?如何使用Zxing應用程序掃描android中的位圖?
0
A
回答
0
它非常簡單,你需要startActivityforResult,類似的來電呼叫其他活動..
在你行動時,掃描被調用,你需要調用以下:
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,你需要捕獲結果
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.
}
}
內容將是您需要的條形碼號碼。
0
ZXing有各種各樣的叉子可以使用。
例如: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;
}
+0
提供的示例是zxing的.NET版本,不適用於Android。 OP沒有提到Xamarin,所以我不認爲這是相關的 – redspidermkv
0
如果你不想堅持到斑馬線,你可以去Barcode Scanning Apis可以從谷歌Play業務7.8版本。這有能力讀取各種條形碼。它可以將圖像作爲位圖或直接掃描條形碼。假設您已從圖庫中獲取圖像並將其轉換爲位圖。請在下面的代碼中找到使用此庫發送要掃描的條形碼圖像的代碼。
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");
}
在你的build.gradle文件,包括根據依賴關係部分如下:編譯 'com.google.android.gms:發揮服務:7.8 +。' 並添加以下清單權限:
<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" />
<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" />
有關此api的詳細用法,請參閱Github Sample,關注Code Lab,Documentation。
相關問題
- 1. 如何使用ZXING掃描結果
- 2. 在Android上使用「Zxing的條形碼掃描儀」應用程序
- 3. ZXing用於Web應用程序的條碼掃描儀
- 4. 如何在WPF應用程序中使用Interop.WIA掃描圖像
- 5. 條碼掃描器應用Android沒有使用ZXing庫
- 6. 如何知道使用zxing掃描結果的類型爲android
- 7. 條形碼掃描器zxing和neoreader在我的應用程序
- 8. 如何在Android中使用zxing應用程序掃描格式PDF 417的條形碼?
- 9. 用Zxing掃描GS1-128
- 10. 在android應用程序中設置zxing 2.0條形碼掃描器
- 11. 如何掃描我的應用程序中的android
- 12. ZXing BarCode掃描儀只掃描應用條碼
- 13. 掃描圖片的應用程序
- 14. 掃描儀Android應用程序
- 15. iBeacon同時掃描(Android應用程序)
- 16. 將Zxing條碼掃描器集成到我的Android應用程序
- 17. iPhone上的Zxing:如何在我的應用程序中掃描包含zxing小部件的qrcode?
- 18. Android中使用ZXING庫的QR碼掃描器
- 19. 使用zxing時獲取掃描結果?
- 20. Zxing Android應用程序
- 21. 如何在c#.net應用程序中使用掃描器
- 22. Zxing使用Xamarin.Forms的Android設備上的條碼掃描器
- 23. 如何檢測Android應用程序的後臺掃描?
- 24. zxing掃描器上的圖層
- 25. 如何將條碼掃描器與android應用程序集成?
- 26. Android Zxing掃描儀和光標
- 27. 如何從Android應用程序內啓動與SocketMobile 7C系列掃描儀掃描程序的連接?
- 28. 在安裝過程中掃描應用程序在android
- 29. 用zxing連續掃描條形碼
- 30. 用ZXing掃描多個條碼
嗨阿希什拉威,謝謝你提出這個問題,但我正在尋找一種方法來發送一個已經在Zxing電話中獲得條形碼的pircture。你知道如何做到這一點?謝謝。 – Carlos