d'abord secrète le chemin de l'image que vous obtenez en base64 String à l'aide de cette fonction
public static String getFileToByte(String path){
Bitmap bm = null;
ByteArrayOutputStream baos = null;
byte[] b = null;
String encodeString = null;
try{
bm = BitmapFactory.decodeFile(path);
baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos);
b = baos.toByteArray();
encodeString = Base64.encodeToString(b, Base64.DEFAULT);
}catch (Exception e){
e.printStackTrace();
}
return encodeString;
}
Save the base64 SharedPreferences
SharedPreferences shre = PreferenceManager.getDefaultSharedPreferences(this);
Editor edit=shre.edit();
edit.putString("image_data",getFileToByte("/path/to/image.jpg"));
edit.commit();
Afficher le dans IMAGEVIEW en cas de besoin
SharedPreferences shre = PreferenceManager.getDefaultSharedPreferences(this);
String previouslyEncodedImage = shre.getString("image_data", "");
if(!previouslyEncodedImage.equalsIgnoreCase("")){
byte[] b = Base64.decode(previouslyEncodedImage, Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
imageView.setImageBitmap(bitmap);
}
peut vous partagez votre code jusqu'à présent –
Je n'ai fait que la partie de l'image de picking, jetez un oeil à t http://stackoverflow.com/questions/31826008/how-to-save-images-to-imageview-using-shared-preferences – Akram