1

I am facing an issue now. Why Bitmap.decodeFile() method is returning null? I tried with the following advice. but the above advice doesn't help me.

For directories reference

Code:

    private File createPhotoFile() throws IOException {
            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
            String imageFileName = "IMG_" + timeStamp + "_";
            File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
            File image = File.createTempFile(imageFileName, ".png", storageDir);
            String mCurrentPhotoPath = image.toString();
    
            BitmapFactory.Options bmOptions = new BitmapFactory.Options();
            Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath,bmOptions);
            //bitmap = Bitmap.createScaledBitmap(bitmap,parent.getWidth(),parent.getHeight(),true);
            Bitmap markedImage = waterMark(bitmap, "your_string", Color.RED, 90, 90, true);
    
            File file = new File("path");
            OutputStream os = new BufferedOutputStream(new FileOutputStream(String.valueOf(markedImage)));
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os);
            os.close();
            return file;
        }
javdromero
  • 1,850
  • 2
  • 11
  • 19
KangDo
  • 79
  • 9
  • Probably similar issue like this [one](https://stackoverflow.com/questions/66101226/nullpointerexception-cant-find-bitmap-from-drawable-on-oppo-device/66113961#66113961) – Darkman May 14 '21 at 06:10
  • 1
    pls reply as answer @Darkman – KangDo Aug 14 '21 at 03:14
  • Try adding `bmOptions.inMutable = true` after you have created it or try this [answer](https://stackoverflow.com/a/62653773/10534012). – Darkman Aug 14 '21 at 05:27
  • 1
    post it as answer for this post, then I will mark your reply as answer – KangDo Aug 14 '21 at 06:02

1 Answers1

1

Try adding bmOptions.inMutable = true after you have created it or try this answer.