Set image on imageview from url resources - android

I have image with url.
How can I assign this resource to an imageview inside my app?

Check this Picasso library and it very easy to load image url on imageview
http://square.github.io/picasso/
Picasso.with(context)
.load(url)
.resize(50, 50)
.centerCrop()
.into(imageView)

Try this :
URL url = new URL("http://yourURL.com/...");
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
imageView.setImageBitmap(bmp);

you must use picasso,
for example
Add this line in build.gradle
compile 'com.squareup.picasso:picasso:2.5.2'
and you code :
ImageView horario = (ImageView)findViewById(R.id.imageView4);
Picasso.with(this).load("http://i.imgur.com/DvpvklR.png").into(horario);
Documentation

Related

How to Load tinyUrl in glide?

I'm trying to load the tinyUrl into an ImageView using Glide. below is the mentioned URL.
String imageUrl = "http://hck.re/3Cm0IX";
Glide.with(context)
.load(imageUrl)
.into(imageView);
apparently this isn't working.
Try to change your imageUrl with the following :
String imageUrl = "https://s3-ap-southeast-1.amazonaws.com/he-public-data/aik_alif4181734.jpg" ;
I was able to solve it using the below URL
https://mindorks.com/android/store/Image-Loaders/aminography/redirectglide

Android - How to Load Image by name using Glide

Hi I'm using Glide to load image from my drawable folder and all works fine, this is my code :
Glide.with(this).load(R.drawable.my_drawable_image_name).into(myImageView);
I'm wondering if there is a way to load the image just by name, something like :
Glide.with(this).load(my_drawable_image_name).into(myImageView);
because i want to get the image name dynamically ,for example from a database...
do you have any suggestion about that?
thanks in advance.
Call getImage method for get Drawable using Name only.
Glide.with(this).load(getImage(my_drawable_image_name)).into(myImageView);
public int getImage(String imageName) {
int drawableResourceId = this.getResources().getIdentifier(imageName, "drawable", this.getPackageName());
return drawableResourceId;
}
Try this:
Glide.with(this)
.load(getResources()
.getIdentifier("my_drawable_image_name", "drawable", this.getPackageName())
.into(myImageView);
Use Uri.
String image = "image.jpg";
String completePath = Environment.getExternalStorageDirectory() + "/" + image;
File file = new File(completePath);
Uri uri = Uri.fromFile(file);
Glide.with(this).load(uri).into(imageView);
You can use the following code to get Bitmap, Drawable from URL using Glide. This code snippet is used to set drawableEnd/drawbleRight for TextView.
Glide.with(context)
.asBitmap()
.load(url)
.into(object : CustomTarget<Bitmap>() {
override fun onResourceReady(
bitmap: Bitmap,
transition: Transition<in Bitmap>?
) {
val drawable: Drawable = BitmapDrawable(
context.resources,
bitmap
)
textView.setCompoundDrawablesWithIntrinsicBounds(
null, null, drawable, null
)
}
override fun onLoadCleared(placeholder: Drawable?) {
}
})
I think you should try this
Glide.with(mContext)
.load(mContext.getResources().getDrawable(R.drawable.my_drawable_image_name))
.placeholder(R.mipmap.icon)
.into(myImageView);
Load method of Glide also accept drawable object as a parameter to load image. You just have to get the drawable object from your drawable image and pass it to the load method.
I wanted rounded-corner of image and that's why I used Glide. In your case, You should use this.
myImageView.setImageDrawable(mContext.getResources().getDrawable(R.drawable.my_drawable_image_name))
If you also want rounded image use this.
Glide.with(mContext)
.load(Glide.with(mContext)
.transform(new FitCenter(), new RoundedCorners((int) mContext.getResources().getDimension(R.dimen._10sdp))
.placeholder(R.mipmap.icon)
.into(myImageView);
Easy way to load image from drawable by using Name
Glide.with(context)
.load(context.getResources().getIdentifier("my_drawable_image_name", "drawable", context.getPackageName()))
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
.placeholder(R.drawable.add_photo_placeholder)
.error(R.color.red)
.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
.into(userPhoto);

How to use setImageURI() in android?

I tried
imageView=(ImageView)view.findViewById(R.id.imageView);
Uri photoUrl = profile1.getPhotoUrl();
imageView.setImageURI(photoUrl);
But i dont see anything.
I am getting url when i am printing it
Thanks in advance
Try to use picasso for this:
Picasso.with(context)
.load(url)
.placeholder(R.drawable.placeholder)
.resize(imgWidth, imgHeight)
.centerCrop()
.into(image);
Try this
Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL("YOUR_URL").getContent());
imageView.setImageBitmap(bitmap);

How to set image file to ImageView or NetworkImageView using Volley in Android?

I have one API,it will give an image as response.Can you suggest me how can set that image to ImageView.Thanks,
`
private static final String URL = "http://someapi";
setting images from api
person.setThumbnailUrl(Picasso.with(getApplicationContext()).load((File) items.get("profileImageLargeUrl")));
This is the way you can set a picture from URL ussing Picasso (you don't need Volley):
ImageView picture = (ImageView) findViewById(R.id.my_image);
String urlImage = "https://...";
...
Picasso.with(this)
.load(urlImage)
.into(picture);
Also you can set other options, like spiner, fit, or errorImage:
.placeholder( R.drawable.progress_animation )
.error(R.drawable.error_image)
.fit()

How to load a image into dynamically created imageview from a URL in android?

I have dynamically created imageview in my app. I tried to load images from URL. But it does not working. I have tried with many methods, and my currently used code is
try {
Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL("http://java.sogeti.nl/JavaBlog/wp-content/uploads/2009/04/android_icon_256.png").getContent());
img.setImageBitmap(bitmap);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
But image is not loaded. What is mistake?
try piccaso library:
ImageView imageView = (ImageView) findViewById(R.id.imageView);
//Loading image from below url into imageView
Picasso.with(this).load("https://java.sogeti.nl/JavaBlog/wp-content/uploads/2009/04/android_icon_256.png").into(imageView);
//change url
take permission in your mainifest:
<uses-permission android:name="android.permission.INTERNET" />
for resize:
Picasso.with(getApplicationContext()).load("https://java.sogeti.nl/JavaBlog/wp-content/uploads/2009/04/android_icon_256.png").resize(100, 100).into(i1);
You can use Universal Image Loader
UIL aims to provide a powerful, flexible and highly customizable instrument for image loading, caching and displaying. It provides a lot of configuration options and good control over the image loading and caching process.
// Load image, decode it to Bitmap and display Bitmap in ImageView (or any other view
// which implements ImageAware interface)
imageLoader.displayImage(imageUri, imageView);
Reference Link - https://github.com/nostra13/Android-Universal-Image-Loader
Use library to load images from url
1. Glide library Refer here:http://coderzpassion.com/android-working-glide-image-loader-library/
2. Picasso library Refer here:http://coderzpassion.com/android-use-picasso-image-loader-library/
3. Volley Library Refer here:http://coderzpassion.com/android-working-volley-library/
Use Simple AQuery library for image loading from internet
// AQuery object
private AQuery aquery;
aquery = new AQuery(context);
ImageView imageView = (ImageView) findViewById(R.id.imageView);
aquery.id(imageView).image("Your image url ",false,false);
Add permission to manifest file
<uses-permission android:name="android.permission.INTERNET" />

Categories

Resources