How to Load tinyUrl in glide? - android

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

Related

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 do I preload multiple images using Glide for later use

I have many images that I want to preload and use later on. I want to make it so that I can load an image, hide it, and then load it again whenever I want.
https://github.com/bumptech/glide/wiki/Loading-and-Caching-on-Background-Threads#into
I have tried following this, but it doesn't work.
Here is my code:
private void loadImage() throws ExecutionException, InterruptedException {
FutureTarget<File> future = Glide.with(this)
.load(R.drawable.image1)
.downloadOnly(500, 500);
File cacheFile = future.get();
Bitmap myBitmap = Glide.with(this)
.load(cacheFile)
.asBitmap()
.centerCrop()
.into(500, 500)
.get();
Glide.with(this).load(myBitmap).into(image_name);
}
I tried using Picasso because I read that this can easily be done in it, but the images take really long to load in Picasso.

Set image on imageview from url resources

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

Categories

Resources