Search code examples
androidstoragephotos

Best practices for photo storage


I want to make an Android application that has the same look as Instagram, which means every profile has a gallery of photos.

My question is about storing and retrieve those photos. I want to know what is the best practice for photo storage in a database (MySQL), more precisely:

  • Should I store photos with original size (2mb for example) or resize them with smaller size?
  • Should I store them with two version (smaller size photo, and normal size photo)?

Solution

  • Saving images in the database looks like overkill, it's not needed. Saving on disk should be fine.

    Although you should focus on your business logic & leave this to image libraries which does this stuff & do best for memory & performance.

    Some famous libs are:

    Almost each library does lots of stuff for you, such as:

    • In memory cache(LRU Cache) - so that UI thread is not blocked from doing I/O operation from disks
    • Disk Cache - To keep images saved for further app sessions, also when memory cache reaches its limit its have to be evicted from it., you can specify disk cache size.
    • Various image scaling strategies
    • Image transformations
    • Clearing up bitmaps for freeing up memory
    • Network operations on background threads
    • Background threads management & so on..

    My suggestion is to go with one of the image library