-1
 URL imageUrl = new URL("http://192.168.0.103:8080/mm/showImage?id=2&fileName=fesc1cc.JPG&imgType=books" );

        //URL imageUrl = new URL(url);
        HttpURLConnection conn = (HttpURLConnection) imageUrl
                .openConnection();

        BufferedReader in = new BufferedReader(
                new InputStreamReader(conn.getInputStream()));
        StringBuffer buffer = new StringBuffer();
        String inputLine;
        while ((inputLine = in.readLine()) != null)
            buffer.append(inputLine);
        in.close();     


        conn.getResponseCode();
        System.out.println(conn.getResponseCode());
        System.out.println(buffer.toString());
        conn.disconnect();

How can I convert the data I am receiving to Bitmap and display it in an image view.

user3840170
  • 26,597
  • 4
  • 30
  • 62
  • Possible duplicate of [How to convert byte array to Bitmap](http://stackoverflow.com/questions/7620401/how-to-convert-byte-array-to-bitmap) – JAAD Aug 30 '16 at 09:11

4 Answers4

2
byte[] imageAsBytes = Base64.decode(myImageData.getBytes());
Bitmap bp = BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length);

OR

byte []bt = buffer.toString().getBytes();
Bitmap i = BitmapFactory.decodeByteArray(buffer.getBytest or buffer.tobytes, 0,bt.length);
Suhas Bachewar
  • 1,230
  • 7
  • 21
-1

you can use picasso library to do thisPicasso.with(context).load(imageUrl).into(imageview);

-1

Use Picasso library instead. Picasso it's very easy to use. Picasso.with(context).load("url").into(ImageView). More info here http://square.github.io/picasso

an_droid_dev
  • 1,136
  • 14
  • 18
-2

More efficient way is using Glide. Glide is a fast and efficient open source media management and image loading framework for Android that wraps media decoding, memory and disk caching, and resource pooling into a simple and easy to use interface.

Usage of library:

  • Add below codes to your gradle file (Module:app)

    repositories {
        mavenCentral() 
    }
    
    dependencies {
        ...
        compile 'com.github.bumptech.glide:glide:3.7.0'
    }
    
  • Use glide to load your url image to imageview

    Glide.with(this).load(imageUrl).into(imageView);
    

For more information please visit https://github.com/bumptech/glide

Good luck.

EDIT:

Glide.with(this)
.load("http://192.168.0.103:8080/mm/showImage?id=2&fileName=fesc1cc.JPG&imgType=books")
.into(imageView);
Batuhan Coşkun
  • 2,961
  • 2
  • 31
  • 48