Capture Image from Camera and Display in Activity

前端 未结 16 1060
悲&欢浪女
悲&欢浪女 2020-11-21 06:43

I want to write a module where on a click of a button the camera opens and I can click and capture an image. If I don\'t like the image I can delete it and click one more i

16条回答
  •  春和景丽
    2020-11-21 07:20

    Use the following code to capture picture using your mobile camera. If you are using android having version higher than Lolipop, You should add the permission request also.

    private void cameraIntent()
        {
              Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
              startActivityForResult(intent, REQUEST_CAMERA);
        }
    
    @override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
         if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {  
                Bitmap photo = (Bitmap) data.getExtras().get("data"); 
                imageView.setImageBitmap(photo);
         }  
    } 
    

提交回复
热议问题