Failed to load image using glide - java

In my application, I was trying to get the thumbnail of a book from google play books API and display it in an image view but somehow what I did is not working.
Glide.with(holder.thumb.getContext())
.load(curThumb)
.into(holder.thumb);
when I used the above method with a local image it worked also thumbnail URL is correct

I tried using Glide v4.0.0-RC1 use RequestOptions to add the placeholder, error image and other options make sure URL(image_url) starts with https, not with HTTP
RequestOptions options = new RequestOptions()
.centerCrop()
.placeholder(R.mipmap.ic_launcher_round)
.error(R.drawable.your_error_image);
RequestOptions to add placeholder, error image and to customize image
Glide.with(this).load(image_url).apply(options).into(imageView);

Related

How to detect if a URL has a file or not?

I'm using Glide to load images in image view from URLs.
If the image is not available in the server and URL doesn't exit/pointing a deleted file then the image view becomes blank..
How to know if URL has a image or not?
//do magic here if/else
Glide
.with(context)
.load(url)
.centerCrop()
.into(myImageView);
Thanks a lot in advance...
Use placeholder() or error() if your objective is to show some local image if the URL does not point to a valid image.
Use RequestListener if you want to learn about failures more generally.
Try out this way.
Glide.with(passContext)
.applyDefaultRequestOptions(
new RequestOptions()
.placeholder(R.drawable.ic_user_default)
.error(R.drawable.ic_user_default)
)
.load(url)
.into(imageview);

Convert Drawable path to URI

I have an image in my #drawable/myimage.jpg of which I would like to load on my ImageView through Glide. Glide however, only accepts Uri's to load the actual image to the ImageView.
Here's the code:
uriImage = Uri.parse("#drawable/myimage.jpg");
//LOADS IMAGES USING GLIDE
Glide.with(AboutActivity.this).load(uriImage).into(imgView);
It somewhat doesn't work. Is there any work-arounds this?
Sorry for being naive, I just started using Android Studio again :)
try this code:
String imageUrl = getURLForResource(R.drawable.personIcon);
// Load image
Glide.with(patientProfileImageView.getContext())
.load(imageUrl)
.into(patientProfileImageView);
it helps you
Simply do this!
Glide.with(AboutActivity.this).load(R.drawable.resouce_name).into(imgView);

using glide with iocipher

I am using glide in order to set images in my GridView, and I am using a library named IOcipher which provides a virtual encrypted disk, so I use info.guardianproject.iocipher.File instead of java.io.file . But glide can't load images, and it has a error saying :
E/Glide: class com.bumptech.glide.load.engine.GlideException: Failed
to load resource
is there any way I could load images? I tried many different ways :(
file.getPath() returns /data/user/0/com.example.zeinab.amndoorbin/app_vfs/myfiles.db/1502685968291.jpg
Glide.with(mContext)
.load(file.getPath()) // Uri of the picture
.into(imageView);

Loading images with Glide from dynamic URL

I use Glide library in my Android project to update avatar from URL that comes in response from API.
The problem is that when I try to load different image (from different URL) to the same imageView it shows me an image that was downloaded first time. (URL forming works fine, I tried it in browser and it shows the needed image)
Here is my code:
EditProfileFragment.xml
public static final String IMAGE_BASE_URL = "http://myapi.com/img/";
String imageUrl = Const.IMAGE_BASE_URL + cb_getProfile.photo; //imageName.jpg
Glide.with(mContext)
.load(imageUrl)
.animate(R.anim.abc_fade_in)
.centerCrop()
.into(mImageView_photo);
Solved this problem by adding a StringSignature when loading image from the URL.
Source
Glide.with(mContext)
.load(imageUrl)
.animate(R.anim.abc_fade_in)
.signature(new StringSignature(String.valueOf(System.currentTimeMillis())))
.centerCrop()
.into(mImageView_photo)
;
Thanks to Yoav Sternberg.

How to effectively load url remote image in ViewPager?

Usually we loading picture is on FragmentPagerAdapter.getItem method.
such as:
Picasso.with(context)
.load(url)
.placeholder(R.drawable.user_placeholder)
.error(R.drawable.user_placeholder_error).into(imageView);
Images then don't show in ViewPager probably never download. But, I want to pre-download images. I've used Picasso.with().load(url).downloadOnly, but this causes multiple unnecessary same url downloading.
I want to pre-download images. If have same url image downloading, it merge downloading interface.
I'm using Glide.It's effective and power.Preload image only use preload() method.

Categories

Resources