我想捕捉扫描时矩形括号下的QR码图像。我知道QR码图像可以很容易地生成和显示,但我的要求是显示扫描的QR码完全相同的图像。
我试过下面的代码:
scan_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
IntentIntegrator integrator = new IntentIntegrator(activity);
integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
integrator.setPrompt("Scan");
integrator.setCameraId(0);
integrator.setBeepEnabled(false);
integrator.setBarcodeImageEnabled(false);
integrator.initiateScan();
}
});
.....
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if (result != null){
Bitmap btm = (Bitmap) data.getExtras().get("data");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
btm.compress(Bitmap.CompressFormat.PNG, 100, stream);
image.setImageBitmap(btm);
if(result.getContents() == null){
android.widget.Toast.makeText(this, "You cancelled the scanning", Toast.LENGTH_LONG).show();
}
else {
android.widget.Toast.makeText(this, result.getContents(), Toast.LENGTH_LONG).show();
}
}
else {
super.onActivityResult(requestCode, resultCode, data);
}
}
但我得到空位图。
答案 0 :(得分:0)
首先,您需要将“setBarcodeImageEnabled”设置为true,以便条形码扫描程序捕获静脉曲张图像。然后在获取条形码结果时,您可以获取图像。
@override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
result.getBitmap()
result.getBitmapWithResultPoints(Color.YELLOW)
}
来源:https://github.com/journeyapps/zxing-android-embedded/issues/143
答案 1 :(得分:0)
在onActivityResult中使用下面的代码获取图像
String path = data.getStringExtra("SCAN_RESULT_IMAGE_PATH");
File file = new File(path);
Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());