开发者

Android: Saving a created bitmap to some equivalent of SharedPreferences?

So I'm having the user create a profile, which includes an avatar. I would like the program to, like the user's name and other info, remember the avatar so it appears as their avatar whenever they use the app. I'd prefer for this bitmap to be saved when created, so the app doesn't need to rebuild the avatar (which is scaled and whatnot) each time the app is started. Is this possible? From the looks of it this wouldn't be able to be saved in SharedPrefs... any idea what the best way to do this would be? Thanks.

Followup: Followed CommonWares's suggestion. Saved to SD... but having trouble calling it back when the app is reloaded.

Currently, in onCreate:

String path = "testapp/images/thumbs/"+m_username+".jpg";
        File file = new File("testapp/images/thumbs/"+m_username+".jpg");
        if(file.exists()) {
            Log.e("TRY TO GET THUMB", "I EXIST");
            m_thumb = BitmapFactory.decodeFile(path);
            Drawable draw = new BitmapDrawable(getResources(), m_thumb);
            m_photoButtonE.setBackgroundDrawable(draw);
        }

Does not find the file, says it does not exist, though when I check my SD card the image is in that exact spot, with the proper file name and everything. Any ideas? Th开发者_如何学JAVAanks all.


Is this possible?

Save it in a file.

From the looks of it this wouldn't be able to be saved in SharedPrefs... any idea what the best way to do this would be?

Save it in a file. If you intend on having multiple avatar files, put a path to the saved avatar file in the SharedPreferences.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜