读书人

android 端运用zxing 扫描sdcard中的二

发布时间: 2012-10-28 09:54:44 作者: rapoo

android 端使用zxing 扫描sdcard中的二维码图片的方法是什么?
可以实现用摄像头扫描二维码图片后一样的效果,就是可以拨打电话,发送EMAIL等,应该调用哪个接口,传什么参数?我现在只能实现
public class PictureActivity extends Activity {
private Button browseButton;
private ImageView qrImage;
private Button scnButton;
private TextView resultText;

@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.picture);
super.onCreate(savedInstanceState);
browseButton = (Button) findViewById(R.id.browseButton);
qrImage = (ImageView) findViewById(R.id.qrImage);
scnButton = (Button) findViewById(R.id.scnButton);
scnButton.setOnClickListener(new ScnButtonListener());
resultText = (TextView) findViewById(R.id.resultText);
browseButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// 进入图库
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
intent.putExtra("return-data", true);
startActivityForResult(intent, 2);
}
});
}

/**
*显示图片
*/
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) {
return;
} else {
switch (requestCode) {
case 2:
Bitmap cameraBitmap = (Bitmap) data.getExtras().get("data");
qrImage.setImageBitmap(cameraBitmap);
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
}
之后怎么调用ZXING的接口解析这个图片并调用相应的功能就不知道了,那位大神知道指点一下,谢谢~!

[解决办法]
使用Zxing下的MultiFormatReader类可以解析多格式二维码,MultiFormatReader的对象有个方法叫decodeWithState(BinaryBitmap bitmap),其中BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));该source是LuminanceSource的子类对象,它是一个通过yuv编码格式数组生成的对象。你现在需要把图片先转换成yuv格式,再通过上述方法识别。RGB转yuv详见:http://user.qzone.qq.com/314154775/infocenter#!app=2&pos=1335403809

读书人网 >Android

热点推荐