3

I want to create an offline app in which the user can add images with image detail. I want to as that what is the best way to store image offline?

Should I use SQLite blob format, SQLite base64 encoded String or should I store it in internal storage or Should I store It in shared Preference. Please help me, If you know any other way then please mention it.

Raj
  • 2,997
  • 2
  • 12
  • 30
  • 1
    `"Should I use SQLite blob format, SQLite base64 encoded String or should I store it in internal storage"` the last option is in most cases the best – pskink Sep 09 '18 at 06:40

2 Answers2

1

Internal storage is best of all. if you want to keep it private ,change format of image and then save otherwise save as it is

0

To save image locally use below code :

private String saveToInternalStorage(Bitmap bitmapImage){
    ContextWrapper cw = new ContextWrapper(getApplicationContext());
     // path to /data/data/yourapp/app_data/imageDir
    File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
    // Create imageDir
    File mypath=new File(directory,"profile.jpg");

    FileOutputStream fos = null;
    try {           
        fos = new FileOutputStream(mypath);
   // Use the compress method on the BitMap object to write image to the OutputStream
        bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos);
    } catch (Exception e) {
          e.printStackTrace();
    } finally {
        try {
          fos.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
    } 
    return directory.getAbsolutePath();
}
Rishav Singla
  • 485
  • 4
  • 10