Android get full size image from camera

后端 未结 1 1920
长发绾君心
长发绾君心 2020-12-15 14:41

I am developing an Android App which uploads an image from the camera or from the device photo gallery to remote site. The latter I have working fine, I can select and uplo

相关标签:
1条回答
  • 2020-12-15 15:21

    I think the problem is that you are still trying to access the thumbnail from the Intent. In order to retrieve the full size image you need to access the file directly. So I'd recommend saving the file name before starting the camera activity and then loading the file at onActivityResult.

    I suggest reading Taking Photos Simply page from the official documentation where you'll find this quote regarding the thumbnail:

    Note: This thumbnail image from "data" might be good for an icon, but not a lot more. Dealing with a full-sized image takes a bit more work.

    Also in the very last section, you'll find the code you need:

    private void setPic() {
        // Get the dimensions of the View
        int targetW = mImageView.getWidth();
        int targetH = mImageView.getHeight();
    
        // Get the dimensions of the bitmap
        BitmapFactory.Options bmOptions = new BitmapFactory.Options();
        bmOptions.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
        int photoW = bmOptions.outWidth;
        int photoH = bmOptions.outHeight;
    
        // Determine how much to scale down the image
        int scaleFactor = Math.min(photoW/targetW, photoH/targetH);
    
        // Decode the image file into a Bitmap sized to fill the View
        bmOptions.inJustDecodeBounds = false;
        bmOptions.inSampleSize = scaleFactor;
        bmOptions.inPurgeable = true;
    
        Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
        mImageView.setImageBitmap(bitmap);
    }
    
    0 讨论(0)
提交回复
热议问题