Images getImageUrl ()

1

I'm loading images like this:

final ImageView img = (ImageView) firstElementView.findViewById(R.id.grid_image);
String src = item.getImageUrl(); 
img.setTag(src);
imageLoader.displayImage(src, img, Utils.getImageLoaderOptions());

But now I need to fetch images by url through an API, that is, the url is not available directly, it is necessary to make some calls first by httpurlconnect() .

Solutions? Do download of the image via httpurlconnect and then show the image? How to do it this way? What other solutions are there?

    
asked by anonymous 24.08.2015 / 11:21

3 answers

1

Solved with:

I used:

Bitmap bitmap = BitmapFactory.decodeStream(conn.getInputStream());

to get the image in Bitmap and then I used:

imageView.setImageBitmap(bitmap);
    
25.08.2015 / 10:38
0

You can download the images in the background so the user does not have to wait for the image to be downloaded and then just load them using the url or the cache system.

Here's an article that talks about it.

link

link

link

I hope I have helped!

Hugs.

    
24.08.2015 / 15:17
0

You can use Picasso .

Picasso is a very popular library used in Android development that solves the whole problem of loading and processing images for you and also simplifies the display of third-party images (such as URLs). The Picasso does from the request ( HTTP ) to the cache of this image for future use.

1) Add Picasso to your build.gradle and synchronize your project:

compile 'com.squareup.picasso:picasso:2.5.2'

2) If you do not, add the internet permission on your AndroidManifest.xml :

<uses-permission android:name="android.permission.INTERNET"/>

3) Create a ImageView any to display your image:

<ImageView
    android:id="@+id/suaImageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

4) Now, in your Activity (or Fragment or any other place that wants to display an image) just reference your ImageView and say to Picasso load your URL:

ImageView suaImageView = (ImageView) findViewById(R.id.suaImageView);

Picasso.with(this)
        .load("http://www.dominio.com.br/imagem.jpg")
        .into(suaImageView);

You also have the possibility to manipulate your image, for example:

Picasso.with(context)
  .load(url)
  //Definindo uma resolução para sua imagem
  .resize(50, 50)
  //Definindo um Scale Type para a sua imagem
  .centerCrop()
  .into(imageView)

Links :

Official site of Picasso : link

GitHub page%: link

    
24.08.2015 / 16:03