-4

Image which is taken from the from custom camera it is not getting display in the imageview in Samsung S4 in Honor 7 phone it is working good.Even image is getting save in sdcard also then also it is not displaying in imageview.

Save Image function

File imageFile;
        // convert byte array into bitmap
        Bitmap loadedImage = null;
        loadedImage = BitmapFactory.decodeByteArray(data, 0,
                data.length);

        // rotate Image
        Matrix rotateMatrix = new Matrix();
        rotateMatrix.postRotate(rotation);
        Bitmap rotatedBitmap = Bitmap.createBitmap(loadedImage, 0,
                0, loadedImage.getWidth(), loadedImage.getHeight(),
                rotateMatrix, false);

        String state = Environment.getExternalStorageState();
        File folder = null;
        if (state.contains(Environment.MEDIA_MOUNTED)) {
            folder = new File(Environment
                    .getExternalStorageDirectory() + "/Image");
        } else {
            folder = new File(Environment
                    .getExternalStorageDirectory() + "/Image");
        }

        boolean success = true;
        if (!folder.exists()) {
            success = folder.mkdirs();
        }
        if (success) {
            java.util.Date date = new java.util.Date();
            imageFile = new File(folder.getAbsolutePath()
                    + File.separator
                    + new Timestamp(date.getTime()).toString()
                    + "Icon.jpg");

            imageFile.createNewFile();
        } else {
            Toast.makeText(mContext, "Image Not saved",
                    Toast.LENGTH_SHORT).show();
            return;
        }
        ByteArrayOutputStream ostream = new ByteArrayOutputStream();
        // save image into gallery
        rotatedBitmap.compress(CompressFormat.JPEG, 50, ostream);

        FileOutputStream fout = new FileOutputStream(imageFile);
        fout.write(ostream.toByteArray());
        fout.close();
        ContentValues values = new ContentValues();

        values.put(Images.Media.DATE_TAKEN,
                System.currentTimeMillis());
        values.put(Images.Media.MIME_TYPE, "image/jpeg");
        values.put(MediaStore.MediaColumns.DATA,
                imageFile.getAbsolutePath());

        mContext.getContentResolver().insert(
                Images.Media.EXTERNAL_CONTENT_URI, values);

        mImagedata = null;

        String filepath = imageFile.getAbsolutePath();
        pref.saveString(Constant.PrefConstants.KEY_USER_IMAGE_PATH, filepath);

displaying the image

File imgFile = new File(pref.getString(Constant.PrefConstants.KEY_USER_IMAGE_PATH));
ivProfileImage.setImageURI(Uri.parse(imgFile.getAbsolutePath()));
Atul Dhanuka
  • 1,453
  • 5
  • 20
  • 56

2 Answers2

0

It is most probably because of the size of the photo. Check the logcat for the warning.

Solution: https://stackoverflow.com/a/17125888/2176401

cancit
  • 172
  • 5
0

For retrieving the image from the SD card add run time permission i.e, READ_EXTERNAL_STORAGE if android version>23

Rashmi Bhandari
  • 448
  • 4
  • 8