user1371486
user1371486

Reputation: 39

What is the Disadvantages of saving images in Database in Android?

I am making an application in which i take a picture from the camera and save in database by compressing in ByteArray but i have read that in if there is various large number of images than precessing of application may be slow by reading images from database so what is the best to store images (either in internal memory or sdcard) and display in ListView?

Thanks

Upvotes: 2

Views: 395

Answers (4)

Raj Shah
Raj Shah

Reputation: 322

The best way is to store images in SDcard with a separate folder. (Using internal memory wont be helpful as it would utilize the space required for installation of other application.)

Every time you load your application read the contents of the folder and populate your list. You need not to maintain seperate database for it. Use Caching Bitmaps for better performance of your code.

Best practice would be as per my opinion

  1. Make sure your cache uses SoftReferences, this way you can make sure that you don't run out of memory, and can always load new bitmaps on the "expense" of losing old ones.
  2. Use the Canvas' drawBitmap methods to draw the large-scale bitmaps smaller.
  3. Make sure you guard against OutOfMemoryError, and notice that it's a subclass of Throwable, and not a subclass of Exception, so a catch(Exception e) clause will not catch it.

Upvotes: 1

Barak
Barak

Reputation: 16393

Storing images in your database will slow down your queries and is generally a bad idea overall.

See this SO question too.

Upvotes: 1

Changwei Yao
Changwei Yao

Reputation: 13101

Save the image to your sdcard. The best approach is to use ImageCache.

cache image.

Upvotes: 1

Lukasz Bator
Lukasz Bator

Reputation: 141

Storing images in any databases is a bad idea, slow takes more space etc. Best option i know of is to store paths or links to those images in database and the actual files on some storage like sdcard or internal storage, if those pictures are big or will take significant amount of space i would place them on sdcard .

Upvotes: 0

Related Questions