0

我正在尝试使用 Zbar 做一个二维码阅读器,但在二维码检测后应用程序崩溃(当结果!= 0 时)

我没有收到错误消息,只有警告:

检查表面信息创建=false formatChanged=false sizeChanged=false visible=false visibleChanged=true surfaceChanged=true realSizeChanged=false redrawNeeded=false left=false top=false

这是我遇到崩溃的代码

public void onPreviewFrame(byte[] data, Camera camera) {
        Camera.Parameters parameters = camera.getParameters();
        Camera.Size size = parameters.getPreviewSize();

        Image barcode = new Image(size.width, size.height, "Y800");
        barcode.setData(data);

        int result = mScanner.scanImage(barcode);

        if (result != 0) {
            mCamera.cancelAutoFocus();
            mCamera.setPreviewCallback(null);
            mCamera.stopPreview();
            mPreviewing = false;
            SymbolSet syms = mScanner.getResults();
            for (Symbol sym : syms) {
                String symData = sym.getData();
                if (!TextUtils.isEmpty(symData)) {
                    Intent dataIntent = new Intent();
                    dataIntent.putExtra(SCAN_RESULT, symData);
                    dataIntent.putExtra(SCAN_RESULT_TYPE, sym.getType());
                    setResult(Activity.RESULT_OK, dataIntent);
                    finish();
                    break;
                }
            }
        }
    }
4

2 回答 2

0

我确实更新了我的代码,效果很好!谢谢大家!

  public void onPreviewFrame(byte[] data, Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    Camera.Size size = parameters.getPreviewSize();

    Image barcode = new Image(size.width, size.height, "Y800");
    barcode.setData(data);

    int result = mScanner.scanImage(barcode);

    if (result != 0) {
        mCamera.cancelAutoFocus();
        mCamera.setPreviewCallback(null);
        mCamera.stopPreview();
        mPreviewing = false;
        SymbolSet syms = mScanner.getResults();
        for (Symbol sym : syms) {
            String symData = sym.getData();
           Log.i("url qr code",symData);
           Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(symData));
           startActivity(browserIntent);

                break;   
        }
    }
}
于 2013-10-29T13:36:26.427 回答
0

试试这个……对于 Qr 阅读器……

public class QRCodeActivityTest extends Activity implements OnQRCodeReadListener {

QRCodeReaderView qrView;
TextView tvQr;
Image_Sql sql;
String Description;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.qrtest_layout);
    qrView = (QRCodeReaderView) findViewById(R.id.qRCodeReaderView1);
    qrView.setOnQRCodeReadListener(this);
    tvQr = (TextView) findViewById(R.id.txtqr);
    sql= new Image_Sql(this);
    sql.Open();
}

@Override
public void onQRCodeRead(String text, PointF[] points) {
    // TODO Auto-generated method stub
    Cursor desc = sql.fetchNameFromTitle(text);
    while (desc.moveToNext()) {
        Description = desc.getString(desc
                .getColumnIndexOrThrow(Image_Sql.IMAGE_DESCRIPTION));
    }
    if(text.equals(""))
    {
        Dialog d = new Dialog(this);
        TextView tv = new TextView(this);
        tv.setText("Please Sync Catalogue TO Display QRCode Image Information");
        d.setContentView(tv);
        d.setTitle("Required Syncing..");
        d.show();
    }else
    {
     tvQr.setText(Description);
    }
}

@Override
public void cameraNotFound() {
    // TODO Auto-generated method stub

}

@Override
public void QRCodeNotFoundOnCamImage() {
    // TODO Auto-generated method stub

}

@Override
protected void onResume() {
    super.onResume();
    qrView.getCameraManager().startPreview();
}

@Override
protected void onPause() {
    super.onPause();
    qrView.getCameraManager().stopPreview();
}

}

于 2013-10-29T13:10:30.413 回答