0

So I have a Preference Acitivity. What I want to do now is that the user opens the Preferences and can choose a picture from the Gallery. This Picture should then be displayed in the Main Activity


I have no idea how to do that, so I hope some of you guys could help me out ;)

Philipp
  • 11
  • 1
  • 5
  • Store the byte representation of the Bitmap into the SharedPrefs? – OneCricketeer Nov 24 '15 at 19:09
  • I have absolutely no idea what you are trying to tell me :P – Philipp Nov 24 '15 at 19:14
  • Once you are able to get the picture from the Gallery, I assume it will be a Bitmap object. Then you can just store that as a String or byte array maybe. I'm just throwing ideas out there - but if you don't know how to get a picture from the gallery, you should've asked that instead. – OneCricketeer Nov 24 '15 at 19:17

1 Answers1

0

Problem can be easily solved by storing the Byte array of the Image in one of the Tags of SharedPreference. To do this you need to convert the Image which is in a Bitmap format to Byte Array. This array can be stored as a text (or Blob) format in SharedPreference or SQLite Database.

When, you need to display the image in any Activity, retrieve the Byte Array and convert it to Bitmap again. This Bitmap can be dynamically assigned to the ImageView of the Activity.

Refer to this answer for the conversion code: How to convert Image into Byte Array in Android

Community
  • 1
  • 1