使用android相机捕获图像[重复]

|                                                                                                                   这个问题已经在这里有了答案:                                                      
已邀请:
我认为这是与仿真器有关的问题,而不是与物理设备有关的问题。 我使用了这段代码,然后得到了一个位图:
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        captureButton = (Button)findViewById(R.id.capture);
        captureButton.setOnClickListener(listener);

        imageView = (ImageView)findViewById(R.id.image);

        destination = new   File(Environment.getExternalStorageDirectory(),\"image.jpg\");
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(requestCode == REQUEST_IMAGE && resultCode == Activity.RESULT_OK) {
            //Bitmap userImage = (Bitmap)data.getExtras().get(\"data\");
            try {
                FileInputStream in = new FileInputStream(destination);
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inSampleSize = 10; //Downsample 10x
                Bitmap userImage = BitmapFactory.decodeStream(in, null, options);
                imageView.setImageBitmap(userImage);
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    }

    private View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            //Add extra to save full-image somewhere
            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(destination));
            Toast.makeText(JMABarcodeScannerActivity.this, Uri.fromFile(destination).toString(), Toast.LENGTH_SHORT).show();
            startActivityForResult(intent, REQUEST_IMAGE);
        }
    };
}
Main.XML
          <?xml version=\"1.0\" encoding=\"utf-8\"?>


          <LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"
          android:orientation=\"vertical\"
          android:layout_width=\"fill_parent\"
          android:layout_height=\"fill_parent\">
      <Button
    android:id=\"@+id/capture\"
    android:layout_width=\"fill_parent\"
    android:layout_height=\"wrap_content\"
    android:text=\"Take a Picture\"
      />
      <ImageView
    android:id=\"@+id/image\"
    android:layout_width=\"fill_parent\"
    android:layout_height=\"fill_parent\"
    android:scaleType=\"centerInside\"
       />
          </LinearLayout>
    

要回复问题请先登录注册