我有一個活動在我的應用程序,必須保存一些數據,並且該數據必須從其他活動,所以我使用SharedPreferences來做到這一點,問題是,當我嘗試要保存的ImageView的位圖:Android SharedPreferences保存位圖
ImageButton imgView = (ImageButton) findViewById(R.id.UserImageButton);
Bitmap bitmap = ((BitmapDrawable)imgView.getDrawable()).getBitmap();
editor.putInt("bitmap", bitmap);
或者直接用:
ImageButton imgView = (ImageButton) findViewById(R.id.UserImageButton);;
editor.putInt("bitmap", ((BitmapDrawable)imgView.getDrawable()).getBitmap());
但doesn't工作。 如何保存?非常感謝
您需要將其保存在字符串base64中,而不是int –
可能的重複[如何在Android中使用sharedpreference存儲圖像?](http://stackoverflow.com/questions/8586242/how-can-i-store -images-using-sharedpreference-in-android) –
請將圖像保存爲普通文件。 – CommonsWare