其中捕获图像存储在android中

时间:2014-03-08 16:33:03

标签: android android-camera-intent

我是android的新手,我找不到解决方案。请解决我的错误。

在此代码中,使用相机意图和捕获后的图像将其设置为图像视图,但来自intent的图像路径返回空指针异常。为什么它会返回null?

这是我的代码:

public class CameraAppActivity extends Activity implements OnClickListener {
    Button btnsetwall;
    ImageButton imgbtntakeph;
    ImageView Imview;
    static final int REQUEST_IMAGE_CAPTURE = 1;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.camera_app);
        Imview = (ImageView) findViewById(R.id.imageView1);
        imgbtntakeph = (ImageButton) findViewById(R.id.imageButton1);
        btnsetwall = (Button) findViewById(R.id.button1);
        imgbtntakeph.setOnClickListener(this);
        btnsetwall.setOnClickListener(this);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.camera_app, menu);
        return true;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.imageButton1:
            dispatchTakePictureIntent();
        case R.id.button1:

            break;
        }

    }

    private void dispatchTakePictureIntent() {
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
            Bundle extras = data.getExtras();
            Bitmap imageBitmap = (Bitmap) extras.get("data");
            Imview.setImageBitmap(imageBitmap);
            Toast.makeText(CameraAppActivity.this,"Here "+ data.getData(), Toast.LENGTH_LONG).show();
        }
    }
} 

0 个答案:

没有答案