【发布时间】:2017-03-12 14:49:15
【问题描述】:
public class MainActivity extends AppCompatActivity {
TextView txt;
Bitmap myBitmap;
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt = (TextView)findViewById(R.id.txt);
ImageView myImageView = (ImageView) findViewById(R.id.imgview);
myBitmap = BitmapFactory.decodeResource(
getApplicationContext().getResources(),
R.drawable.barcode);
myImageView.setImageBitmap(myBitmap);
btn = (Button) findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bar();
}
});
}
public void bar(){
BarcodeDetector detector =
new BarcodeDetector.Builder(getApplicationContext())
.setBarcodeFormats(Barcode.DATA_MATRIX | Barcode.QR_CODE)
.build();
if(!detector.isOperational()){
txt.setText("Could not set up the detector!");
return;
}
Frame frame = new Frame.Builder().setBitmap(myBitmap).build();
SparseArray<Barcode> barcodes = detector.detect(frame);
Barcode thisCode = barcodes.valueAt(0);
txt.setText(thisCode.rawValue);
Toast.makeText(getApplicationContext(), thisCode.rawValue.toString(), Toast.LENGTH_SHORT).show();
}
}
barcode.png 是:
food barcode
每当我使用它作为位图运行应用程序时,它都会崩溃并给出out of bounds array 0 异常。我不确定为什么会发生这种情况,但应用程序不断崩溃。
它可以检测方形条码,但它无法检测到这个。这里有什么问题?
LOGCAT: Logcat from app
【问题讨论】:
-
你能发一下logcat吗?
-
@prasad,我已经添加了 logcat
-
请将其发布在问题中,而不是作为某些异地文档共享站点的链接。而不是作为“pdf”文件,大声喊叫!
标签: java android android-vision