1
 @Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.btn_read_palm:
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(cameraIntent, CAMERA_REQUEST);
            break;
        case R.id.btn_read_from_existing:
            Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(intent, RESULT_LOAD_IMG);
            break;
    }
}

Here getting selectedImageUri = content://media/external/images/media/2997 and
path = /storage/emulated/0/DCIM/Camera/IMG_20170510_132342860.jpg

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        switch (requestCode) {
            case CAMERA_REQUEST:
                Bitmap photo = (Bitmap) data.getExtras().get("data");
                saveAndShowPictureDialog(photo);
                break;
            case RESULT_LOAD_IMG:
                Uri selectedImageUri = data.getData();
                String path = getRealPathFromURI(this, selectedImageUri);
                if (path != null)
                    showImageDialog(path);
        }
    }
}

getRealPathFromURI function returning correct path.

 public String getRealPathFromURI(Context context, Uri contentUri) {
    Cursor cursor = null;
    try {
        String[] proj = {MediaStore.Images.Media.DATA};
        cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
        assert cursor != null;
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}


private void showImageDialog(String pictureFile) {
    // custom dialog
    final Dialog dialog = new Dialog(this, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
    dialog.setContentView(R.layout.image_dialog);
    dialog.setTitle("Image");
    // find the imageview and draw it!
    ImageView image = (ImageView) dialog.findViewById(R.id.image);
    Bitmap bmImg = BitmapFactory.decodeFile(pictureFile);

here i am getting a black screen/image on imageview when setting Image Bitmap from the picture file.

    image.setImageBitmap(bmImg);
    Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
    // if button is clicked, close the custom dialog
    dialogButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
    dialog.show();
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
harsh bangari
  • 417
  • 6
  • 19
  • The resilution of the image you selected is too hight. Select a much smaller image. – greenapps May 12 '17 at 18:12
  • 2
    Does this answer your question? [Android : Maximum allowed width & height of bitmap](https://stackoverflow.com/questions/15313807/android-maximum-allowed-width-height-of-bitmap) – Luciano Mar 30 '20 at 05:53

2 Answers2

0

Try the following instead of Bitmap bmImg = BitmapFactory.decodeFile(pictureFile);?

            Bitmap bmImg;
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            bmImg = BitmapFactory.decodeFile(selectedImagePath, options);
            image.setImageBitmap(bmImg);
Belladonna
  • 99
  • 1
  • 8
0

ImageView's have a display resolution limit based on OpenGL. Normally this limit is about 2048 x 2048. If you go above that limit, the ImageView will just show black and throw no error.

This is particularly irritating with gallery images / camera images, since those can be very high resolution.

It's also irritating because the OpenGL limit can vary heavily based on the device. Therefore, the error is very hard to reproduce.

You can query the exact maximum resolution with something like this:

int[] maxSize = new int[1];
GLES10.glGetIntegerv(GL10.GL_MAX_TEXTURE_SIZE, maxSize, 0);

This answer goes into a little more detail about OpenGL and these limitations with regard to maximum width and height of a bitmap

Luciano
  • 1,119
  • 12
  • 18