我將圖像轉換爲字符串並將該字符串存儲在sharedpreferences中。然後稍後在其他活動中,我想獲取該字符串轉換回位圖並將其顯示在圖像視圖中。如果沒有從sharedpreference中獲取任何內容,也爲precausion我想將ic_launcher設置爲我的ImageView中的默認圖像。從sharedpreference獲取字符串,轉換爲位圖,在imageview中顯示
這是我如何努力完成上述任務。
String pic = shared.getString("UserPic","");
Log.i("picstring-verifydetail" , "picstring : "+pic);
if (pic != null && pic != "") {
try {
userpic = ImageHelper.stringToImage(pic);
profilepic.setImageBitmap(userpic);
} catch (IOException e) {
Log.e("picsetting", e.toString());
e.printStackTrace();
}
}
else
{
Bitmap defaultImage = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);
profilepic.setImageBitmap(defaultImage);
}
我也喜歡存儲一些名稱和值是成功抓取,但字符串圖像不從sharedpreferences越來越牽強。它總是會去其他部分,然後再次出現錯誤:profilepic.setImageBitmap(defaultImage);
上的「未找到源」。我搜索了logcat,但沒有發現錯誤。
請幫助完成這2個任務。
感謝&問候,
Sourabh古普塔
你是如何保存它的喜好? –