how can I store image in Shared Preferences and retrieve it?
I am developing an android application. In my application, I am displaying images from url using xml parsing. I want to store images in device's Shared Preference开发者_StackOverflow社区s. How can I store image in shared preferences and retrieve image from shared preferences? How is it possible?
Thanks All.
I'll try to give you an idea, i use to store temporary object using shared preference, so use kind of serialization, i wrote my own Base64 Encoder/Decorer and basically.
Step 1) Encode your Bitmap or JP..etc
Step 2) Put it in Shared pref as string. (encoded string)
Step 3) Retrive your Encoded object from SharedPref Step 4) Decode it and you will have your object Back (your pic).
It's not that hard to do it.
Why would you store it in the SharedPreferences
? That is not the correct location for storing images.
You should cache them on the external storage if one is available and if not then you should try to store them on the internal storage but watch out when working with the internal storage as you generally won't have as much space as on the external storage.
Check out this article on using the external storage.
精彩评论