0

I've seen a huge number of related questions, but none of them actually answer the question, and many just use code snippets out of context with undefined variables.

I need to store images in a database (which to the best of my knowledge I should do using Base64 encoded strings), and use them as Image objects in the android code.

From what I've worked out, I need to convert the Image to a Bitmap, then Bitmap can be turned into a Base64 string. But I can't for the life of me work out how to convert the Image into a Bitmap. Any help is appreciated.

EDIT: While other questions do convert an image from a file location to a string, I don't have a file location. The image is stored solely as an instance of android.media.Image, and I don't know how to access that using a file path or anything similar.

EDIT 2: Okay, so here's my setup: the images will be stored in Firebase database as Base64 encoded strings. When I need them, I will pull the string from there and convert it into an Image object, which is just a variable I have temporarily. They are never stored locally, the only time they're on the actual app they are the Image object.

9
  • Possible duplicate of How to convert image into byte array and byte array to base64 String in android? Commented Oct 30, 2017 at 0:20
  • @NorthernPoet that question starts with a file path for an image; I don't have the image locally stored, I only have an Image object. Commented Oct 30, 2017 at 0:21
  • @Vedvart1 where your image is located? in drawable folder? or you are loading from web url? Commented Oct 30, 2017 at 4:33
  • The image is stored solely as an instance of android.media.Image, . Where is it stored that way? Commented Oct 30, 2017 at 8:53
  • @LokeshDesai They aren't stored on the phone or loaded from a URL; they are stored in an online database as strings. See my new edit. Commented Oct 30, 2017 at 20:45

1 Answer 1

3

Just convert your base64 string into bitmap than load that bitmap into imageview using below code

byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); 
image.setImageBitmap(decodedByte);
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, this method is adequate enough.
@Vedvart1 great if u face any issue inform me...enjoy coding

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.