0

I want to save some images in internal storage. Here is my code:

Bitmap bitmap = ((BitmapDrawable)iv_add.getDrawable()).getBitmap();
            File file = getApplicationContext().getDir("Images",MODE_PRIVATE);
            file = new File(file, "UniqueFileName"+".jpg");
            try{
                OutputStream stream = null;
                stream = new FileOutputStream(file);
                bitmap.compress(Bitmap.CompressFormat.JPEG,100,stream);
                stream.flush();
                stream.close();
            }catch (IOException e)
            {
                e.printStackTrace();
            }

As I understood, the picture needs to go into internal_storage/android/data/project_name/file. When I choose a picture from my gallery and click the button to save it, nothing happens and the program starts lagging. What can I do?

  • Hi and welcome to stackoverflow. this question asked before. try this solution :https://stackoverflow.com/a/17674787/3973113 – Ben Feb 16 '20 at 17:56
  • Hi. I've already tried those solutions many times, but it didn't work. I even tried them on 2 different versions of Android Studio: v3.6.0 Canary 12 and v3.5.0 – Hayk Nazaryan Feb 16 '20 at 18:00
  • The path you mention does not exist. Take a look at `file.getAbsoluthePath()` for the real path. – blackapps Feb 16 '20 at 18:02
  • Further: if one picks an image file from 'gallery' one does not get a bitmap. So where your bitmap comes from is undefined. – blackapps Feb 16 '20 at 18:04
  • `nothing happens and the program starts lagging` It is unclear what should happen or what the user should perceive. – blackapps Feb 16 '20 at 18:06
  • Can You please give me an example of file.getAbsoluthePath() in an actual peace of code? Because I don't really understand where to put it... – Hayk Nazaryan Feb 16 '20 at 18:24
  • Log or Toast the value. – blackapps Feb 16 '20 at 22:21
  • Thanks a lot for helping me. I was looking for the file in the wrong path, but now I found the correct one – Hayk Nazaryan Feb 18 '20 at 17:53

0 Answers0