-2

Actually i can easily get the textView from my server by using setText. i dont know how to set image from server.

image = (ImageView)findViewById(R.id.imgView);

and i get string of that image

profileimage = jsonObj.getString("profile_img");

then i used setImageBitmap to set image.

byte[] data = Base64.decode(profileimage, 0);
Bitmap b = BitmapFactory.decodeByteArray(data,0,0, null);
image.setImageBitmap(b);

its not displaying by using . need a solution. i am using android eclipse.

4 Answers4

1

may be this will help you,

add this library in your build gradle

compile 'com.github.bumptech.glide:glide:3.7.0'

than your activity,

Glide.with(mContext).load(profileimage).into(imageView);
Jinal Awaiya
  • 441
  • 3
  • 14
0

You may use Glide or Picasso for image loading. Sample code using Picasso looks like Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);

ThunderDragon
  • 613
  • 3
  • 13
  • 31
0

you can use Glide or Picasso

1.esay setup 2.image to memory and do the cache 3.optimize images for size ImageView

Picasso.with(context)
        .load(imageUrl)
        .placeholder(R.drawable.ic_default)
        .config(Bitmap.Config.RGB_565)
        .fit()
        .centerCrop()
        .into(imageView);



Glide.with(context)
        .load(imageUrl)
        .placeholder(R.drawable.ic_default) 
        .diskCacheStrategy(DiskCacheStrategy.ALL) 
        .fitCenter()
        .into(imageView);
Rasoul Miri
  • 11,234
  • 1
  • 68
  • 78
0

First of all you need to know about Bitmap , Its a class that is used to decode local file. And by local i mean which are reside in device internal or sd card storage . And here you need to load a image from cloud with a Url . So you need to download that image first then get Bitmap from it and then set it to image view . This is a often task so some great developers already made a bunch of libraries for this purpose to make it bread and butter for us . Below are some references you can use Its easy and optimized :

Glide

Picasso

Fresco

ADM
  • 20,406
  • 11
  • 52
  • 83
  • i am using eclipse how can solve this ?? need a brief steps if u please. – Karnesh_Prabhu Jul 10 '17 at 06:20
  • There is no issue with IDE whether you are using eclipse or AS . Each IDE has its own Build method . To add those library in eclipse you need to download the project or you can look for a .jar. [this](https://stackoverflow.com/a/3643015/4168607) will help for further steps. Suggesting you to use Android Studio for android development . – ADM Jul 10 '17 at 07:23
  • okay but i dont know to download the image and getting bitmap from it. help me ADM :) i am new android developer – Karnesh_Prabhu Jul 11 '17 at 04:37
  • Use Glide library and follow the answer below by Rasoul Miri or read about the glide on github . – ADM Jul 11 '17 at 04:44