Get image Uri + thumbnail of the picture shot with camera in Android

前端 未结 1 1409
走了就别回头了
走了就别回头了 2020-12-18 01:17

I want to update an ImageView with a picture I make with the build-in Android camera. I use the following code:

void getPhoto() {
        Intent intent = new         


        
相关标签:
1条回答
  • 2020-12-18 01:55

    I put my own URI in the intent to tell it where to save, then you know where it is, not sure there is any other way. Create some fields for your file.

    private String imagePath = "/sdcard/Camera/test.jpg";
    private File originalFile;
    

    Then initialize the file.

    originalFile = new File(imagePath);
    

    Now start the Camera app with the intent, passing the URI as an extra.

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        Uri outputFileUri = Uri.fromFile(originalFile);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        startActivityForResult(intent, RESULT_CAPTURE_IMAGE); 
    

    In the onActivityResult() extract the URI

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
                if (requestCode == RESULT_CAPTURE_IMAGE && resultCode == Activity.RESULT_OK) {
            mBitmap = BitmapFactory.decodeFile(originalImagePath, BitmapFactoryOptions);  //set whatever bitmap options you need.
    

    So you can now build a bitmap using createBitmap or use file path for whatever you need

    0 讨论(0)
提交回复
热议问题