我怎么能存储图像的共享preferences并检索它? [英] how can I store image in Shared Preferences and retrieve it?

查看:137
本文介绍了我怎么能存储图像的共享preferences并检索它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android应用程序。在我的应用程序,我使用显示XML解析从URL的图像。我想在存储设备的共享preferences图像。我怎么能存储在共享preferences图像和检索共享preferences形象?这怎么可能?

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 Preferences. How can I store image in shared preferences and retrieve image from shared preferences? How is it possible?

谢谢大家。

推荐答案

我会尽力给你一个想法,我用使用共享preference存储临时对象,所以用一种系列化的,我写我自己Base64编码恩codeR / Decorer和基本。

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.

步骤1)恩code位图或JP..etc结果
步骤2)放入共享$ P $粉煤为字符串。 (EN codeD字符串)

Step 1) Encode your Bitmap or JP..etc
Step 2) Put it in Shared pref as string. (encoded string)

步骤3)共享preF撷取您的恩codeD对象
步骤4)德code它,你将有你的对象返回(你的PIC)。

Step 3) Retrive your Encoded object from SharedPref Step 4) Decode it and you will have your object Back (your pic).

这并不难做到这一点。

这篇关于我怎么能存储图像的共享preferences并检索它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆