android: Take camera picture without “save” / “delete” confirmation

前端 未结 6 1111
醉酒成梦
醉酒成梦 2020-12-01 11:26

I want to display an image taken from the camera in an ImageView using

Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
         


        
6条回答
  •  渐次进展
    2020-12-01 11:39

    You can use the solution of AnujMathur_07, but if you do not want work with paths and files, in the method onPictureTaken, you can return the bitmap:

     @Override
                public void onPictureTaken(byte[] data, Camera camera) {
                    Toast.makeText(getApplicationContext(), "Picture Taken",
                            Toast.LENGTH_SHORT).show();
                    Intent intent = new Intent();
    
                Bitmap bmp = BitmapFactory.decodeByteArray(data, 0,
                        data.length);
    
                intent.putExtra("image", bmp);
                setResult(RESULT_OK, intent);
                camera.stopPreview();
                if (camera != null) {
                    camera.release();
                    mCamera = null;
                }
                finish();
            }
    

    And in the method onActivityResult you can get bitmap:

     Bundle extras = data.getExtras();
     Bitmap imageBitmap = (Bitmap) extras.get("image");
    

提交回复
热议问题