How to take a picture to show in a `ImageView` and save the picture?

后端 未结 4 739
执笔经年
执笔经年 2020-12-28 23:16

I need to take a picture with the camera, save the picture, show in ImageView and when I click the Imagevie

4条回答
  •  情深已故
    2020-12-29 00:08

    Try this, to save image to file explorer:

       public void captureImage(View v) {
        Intent camera_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            File f = new File(Environment.getExternalStorageDirectory(), "image.png");
            camera_intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
            startActivityForResult(camera_intent, CAMERA_PIC_REQUEST);
    }
    
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
    
            if(resultCode== Activity.RESULT_OK){
                f = new File(Environment.getExternalStorageDirectory().toString());
                for (File temp : f.listFiles()) {
                    if (temp.getName().equals("image.png")) {
                        f = temp;
                        imagePath= f.getAbsolutePath();
                        Bitmap thumbnail= BitmapFactory.decodeFile(f.getAbsolutePath(), options);
    imgView.setImageBitmap(thumbnail);
    }
    

    You can fetch image from path "imagePath" whenever you have to display it.

提交回复
热议问题