Search in sources :

Example 1 with BitmapDecoder

use of com.google.zxing.decode.BitmapDecoder in project QRCode by 5peak2me.

the class CaptureActivity method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (resultCode == RESULT_OK) {
        final ProgressDialog progressDialog;
        switch(requestCode) {
            case REQUEST_CODE:
                // 获取选中图片的路径
                Cursor cursor = getContentResolver().query(intent.getData(), null, null, null, null);
                if (cursor.moveToFirst()) {
                    photoPath = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
                }
                cursor.close();
                progressDialog = new ProgressDialog(this);
                progressDialog.setMessage("正在扫描...");
                progressDialog.setCancelable(false);
                progressDialog.show();
                new Thread(new Runnable() {

                    @Override
                    public void run() {
                        Bitmap img = BitmapUtils.getCompressedBitmap(photoPath);
                        BitmapDecoder decoder = new BitmapDecoder(CaptureActivity.this);
                        Result result = decoder.getRawResult(img);
                        if (result != null) {
                            Message m = mHandler.obtainMessage();
                            m.what = PARSE_BARCODE_SUC;
                            m.obj = ResultParser.parseResult(result).toString();
                            mHandler.sendMessage(m);
                        } else {
                            Message m = mHandler.obtainMessage();
                            m.what = PARSE_BARCODE_FAIL;
                            mHandler.sendMessage(m);
                        }
                        progressDialog.dismiss();
                    }
                }).start();
                break;
        }
    }
}
Also used : BitmapDecoder(com.google.zxing.decode.BitmapDecoder) Bitmap(android.graphics.Bitmap) Message(android.os.Message) ProgressDialog(android.app.ProgressDialog) Cursor(android.database.Cursor) DecodeThread(com.google.zxing.decode.DecodeThread) Result(com.google.zxing.Result)

Example 2 with BitmapDecoder

use of com.google.zxing.decode.BitmapDecoder in project QRCode by 5peak2me.

the class CaptureActivity method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (resultCode == RESULT_OK) {
        final ProgressDialog progressDialog;
        switch(requestCode) {
            case REQUEST_CODE:
                // 获取选中图片的路径
                Cursor cursor = getContentResolver().query(intent.getData(), null, null, null, null);
                if (cursor.moveToFirst()) {
                    photoPath = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
                }
                cursor.close();
                progressDialog = new ProgressDialog(this);
                progressDialog.setMessage("正在扫描...");
                progressDialog.setCancelable(false);
                progressDialog.show();
                new Thread(new Runnable() {

                    @Override
                    public void run() {
                        Bitmap img = BitmapUtils.getCompressedBitmap(photoPath);
                        BitmapDecoder decoder = new BitmapDecoder(CaptureActivity.this);
                        Result result = decoder.getRawResult(img);
                        if (result != null) {
                            Message m = mHandler.obtainMessage();
                            m.what = PARSE_BARCODE_SUC;
                            m.obj = ResultParser.parseResult(result).toString();
                            mHandler.sendMessage(m);
                        } else {
                            Message m = mHandler.obtainMessage();
                            m.what = PARSE_BARCODE_FAIL;
                            mHandler.sendMessage(m);
                        }
                        progressDialog.dismiss();
                    }
                }).start();
                break;
        }
    }
}
Also used : BitmapDecoder(com.google.zxing.decode.BitmapDecoder) Bitmap(android.graphics.Bitmap) Message(android.os.Message) ProgressDialog(android.app.ProgressDialog) Cursor(android.database.Cursor) Result(com.google.zxing.Result)

Aggregations

ProgressDialog (android.app.ProgressDialog)2 Cursor (android.database.Cursor)2 Bitmap (android.graphics.Bitmap)2 Message (android.os.Message)2 Result (com.google.zxing.Result)2 BitmapDecoder (com.google.zxing.decode.BitmapDecoder)2 DecodeThread (com.google.zxing.decode.DecodeThread)1