I Want to load image from json in my assest as a string and then pass it to an imageview. How to do it?
Asked
Active
Viewed 54 times
4 Answers
1
Say your json is something like:
const book = {
id: 1,
title: "my title",
img:"/image/file.png",
...
}
...
you may pass that object directly in your image tag:
eg.
<img src="{book.img}" />
NJAS
- 53
- 5
0
You can use Library like Glide and Picasso for load image in imageview as a string Please check below link How to load Image into ImageView from Url using Glide v4.0.0RC1
Sumit Kumar
- 215
- 6
0
If you want to store the whole image in your JSON, than you could use base64 to convert from byte[] to String and vice versa. Java has base64 encoders and decoders in it's util packages. Wiki page: https://en.wikipedia.org/wiki/Base64.
AlexAlbu
- 66
- 3
0
Get image as byteArray from JSON, then set it into imageView.
//byte[] imageData
ImageView imgViewer = (ImageView) findViewById(R.id.image);
Bitmap bm = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
imgViewer.setImageBitmap(bm);
Milad Bahmanabadi
- 1,047
- 11
- 23