我想从我的SD卡上的图像解码qr代码,我不想使用外部扫描仪。我用Zxing库。我有一些代码
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView txt = (TextView)findViewById(R.id.textView1);
ImageView img=(ImageView)findViewById(R.id.imageView1);
img.setImageResource(R.drawable.qr);
Bitmap bt = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getAbsolutePath()+"/cameraApplicationSe/qr.png");
img.setImageBitmap(bt);
int [] pix = new int[bt.getWidth() * bt.getHeight()];
LuminanceSource qr=new RGBLuminanceSource(bt.getWidth(),bt.getHeight(),pix);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(qr));
Reader reader = new MultiFormatReader();
Result result;
try {
result = reader.decode(bitmap);
txt.setText(result.getText());
} catch (NotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
txt.setText("NotFoundException");
} catch (ChecksumException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
在Manifest文件中添加读写外部存储的用户权限。我在TextView中收到的所有尝试 - NotFoundException。在图像中我有QR码,独立创建。在网站上。 哪里有错误?求你帮帮我。