【问题标题】:Focus and scan barcode lines from android Camera从 android 相机聚焦和扫描条码线
【发布时间】:2012-08-27 17:52:50
【问题描述】:

我正在使用以下扫描条码线。

private Camera mCamera;
    private CameraPreview mPreview;
    public static final int MEDIA_TYPE_IMAGE = 1;
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.newmain);

        Button captureButton = (Button) findViewById(R.id.button_capture);

//      Create an instance of Camera
        mCamera = getCameraInstance();

//      Create our Preview view and set it as the content of our activity.
        mPreview = new CameraPreview(this, mCamera);
        FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
        preview.addView(mPreview);
        final PictureCallback mPicture = new PictureCallback() 
        {
            public void onPictureTaken(byte[] data, Camera camera)
            {
                Intent intent = new Intent("http://zxing.appspot.com/scan");
//              Intent intent = new Intent("com.google.zxing.client.android.SCAN");
                intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
                startActivityForResult(intent, 0); 
            }
        };

            captureButton.setOnClickListener(new View.OnClickListener() 
            {
                public void onClick(View v) 
                {
                    Intent intent = new Intent("http://zxing.appspot.com/scan");
//                  Intent intent = new Intent("com.google.zxing.client.android.SCAN");
                    intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
                    startActivityForResult(intent, 0); 

                    // get an image from the camera   
//                    System.out.println("Photo Taking!");
//                    mCamera.takePicture(null, null, mPicture);
                }
            });
    }

然后我使用以下方法将intent传递给zxing sdk..

public void onActivityResult(int requestCode, int resultCode, Intent intent) 
      {
          if (requestCode == 0)
          {
              TextView tvStatus=(TextView)findViewById(R.id.tvStatus);
              TextView tvResult=(TextView)findViewById(R.id.tvResult);
              if (resultCode == RESULT_OK) 
              {
                  String contents = intent.getStringExtra("SCAN_RESULT");
                  String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
                  tvStatus.setText(intent.getStringExtra(format));
                  tvResult.setText(intent.getStringExtra(contents));
                  Toast.makeText(getApplicationContext(), "Content:" + contents + " Format:" + format , Toast.LENGTH_LONG).show();
              }
              else if (resultCode == RESULT_CANCELED) 
              {
                  tvStatus.setText("Press a button to start a scan.");
                  tvResult.setText("Scan cancelled.");
              }
          }
      }

但我无法将相机焦点放在条码线上.. 如果我能得到一些关于如何将相机聚焦在条形码线上的帮助,我将不胜感激,这样我就可以将意图传递给 zxing sdk .. 此外,将不胜感激某些 Android sdk 上用于扫描条形码行的 cmets。 提前谢谢..

【问题讨论】:

    标签: android barcode-scanner


    【解决方案1】:

    为什么要拍照发给zxing?您可以直接要求Zxing App打开相机并读取条形码。看我的回答here

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多