Picasso doesnt load images if I use imageURL reference but loads when I use actual url e.g. "http://i2.cdn.turner.com/cnnnext/dam/assets/161017171526-cafe-neo-cup-super-169.jpg"
String imageURL = feedItem.getImageUrl();
Picasso.with(getContext()).load(imageURL).resize(600, 0).into(newsImage);
Log.i(LOG_TAG,"Image url is: "+imageURL);
Here is the log output from above
10-20 22:32:00.141 13274-13274/bw.co.fus.print I/NewsFeedAdapter: Image url is: "http://i2.cdn.turner.com/cnnnext/dam/assets/161017171526-cafe-neo-cup-super-169.jpg"
Picasso loads when I use this
Picasso.with(getContext()).load("http://i2.cdn.turner.com/cnnnext/dam/assets/161017171526-cafe-neo-cup-super-169.jpg").resize(600, 0).into(newsImage);
I have tried different resize options, including .fit() and without, also .centercrop(). Also thought it could be null but clearly its not.
Please double check if your feedItem#imageUrl variable doesn't have quotation marks on either side. According to your log output, it has. If you are passing URI to Picasso as a String, it should look like
http://whatever.com/...
and not
"http://whatever.com/..."
Also, use debugger to find out more about what's inside of your model for this specific time (beware, if you are using Realm, it will shown as null, here's why)
Related
I am developing an application in which i am using Glide Library to load image from server. But Unfortunately this is not working and i am completely unaware about this and trying to solve this issue since last two days.
this is my code.
Glide.with(this).load(response.getBank_cash_deposit().getData().getAttributes().getAttachment()).into(mSelectedImage);
Try Log your image response. you're getting correct image URL or not.
If the image URL is correct then check whether there is space in your image URL or not.
If the space is exists then replace space in your URL String with %20 with the help of string.replace() function.
String image=response.getBank_cash_deposit().getData().getAttributes().getAttachment();
Log.d("Image",image);
if space exists
then
image.replace(" ","%20");
Also check image url on web.
I have an android app which has profile image.
The user can edit his/her profile image.
I'm using Picasso to load images, but every time I load profile image, Picasso loads old image.
When I upload profile image I don't change it's url, so profile image url for every user is constant.
First question: should I change profile image url every time user change profile image?
Second question: When user change his/her profile image I invalidate Picasso to load new image using this code:
picassoInstance.load(url)
.networkPolicy(NetworkPolicy.NO_CACHE)
.transform(new CircleTransform())
.placeholder(dr)
.into(imageView);
But Picasso show me the old one.
And one more thing:
I load image url into imageView without calling networkPolicy method at first.
How should I handle this problem?
Every Image has different name, whenever new image uploaded you have to update your image Url
Eg. current url : https://photographylife.com/nikon-d810-high-resolution-image-samples
where Image name is : nikon-d810-high-resolution-image-samples
and after uploaded new image, name will be different for example : image-sample
so you need to update that image Url : https://photographylife.com/image-sample with new name
try this, i telling you cause im doing the same hope this will help you!
So lets just discuss one by one:
Should I change profile image url every time user change profile
image?
No. You might think of other ways around. In my case, I download the picture each time the url changes with a specific name of the user (as we're considering profile picture). So when I loaded the image with Picasso I passed the file path instead of the URL so that, it won't fetch from the URL each time. Picasso doesn't do that either actually. It maintains a cache. If the file doesn't exist, just put a placeholder.
When user change his/her profile image I invalidate Picasso to load
new image using this code:
I don't see any invalidate code here in your code. I would refer to this link to see how they've solved the cache problem.
I load image url into imageView without calling networkPolicy method
at first.
So if you fetch the image from the external storage, I don't think there's a necessity to do so.
And another suggestion is to use Glide in these cases. This is almost the same thing as Picasso, but personally I like to use Glide instead of Picasso.
Hope that helps.
Using Glide instead of Picasso because Glide recommended by google
http://inthecheesefactory.com/blog/get-to-know-glide-recommended-by-google/en
Preventing for caching in Glide
Glide.with(DemoActivity.this)
.load(Uri.parse("file://" + imagePath))
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.into(mImage);
Add this class to the com.squareup.picasso package.
package com.squareup.picasso;
public class PicassoTools {
public static void clearCache (Picasso p) {
p.cache.clear();
}
}
Because cache has package visibility, this util class can clear the cache for you. You just have to call it:
PicassoTools.clearCache(Picasso.with(context));
I find where problem is:
I turned down disk cache but not memory cache. I should use this code:
picassoInstance.load(url)
.networkPolicy(NetworkPolicy.NO_CACHE)
.memoryPolicy(MemoryPolicy.NO_CACHE)
.transform(new CircleTransform())
.placeholder(dr)
.into(imageView);
I use this link to:
picasso-influencing-image-caching
Thanks everybody
You need to invalidate the file before loading use the code given below:
Picasso.with(getActivity()).invalidate(file);
To know more details kindly study the Picasso documentation from their website.
I'm using the Picasso library to dynamically load images from an API call.
Certain urls seem to return a malformed URL, for example: "http://imagesite.com/image.1241123.gif which crashes the app.
Picasso.with(activity).load(image)
.centerCrop()
.error(R.drawable.icon01)
.resize(50, 50)
.into(icon);
Looking at the documentation, I assumed the .error() parameter would handle this, but Picasso seems to see it as a valid URL, even though it won't return an image. I've also tried using the Picasso.Builder but I continue to get the same errors. Any suggestions?
picasso don't load gif image for that you have to use Glide library.
Check this link it might help you : http://inthecheesefactory.com/blog/get-to-know-glide-recommended-by-google/en
and you get library from : https://github.com/bumptech/glide
error() will handle issues where the URL is well formed but for some reasons it cannot display the image.
If you have malformed url it means the problem is your data. Remember garbage in , garbage out.
Use Uri.parse() before loading it to picasso, then handle the thrown exception: better fix your data.
I'm using a specific url to obtain an image online, but the url itself automatically changes every few minutes.
I'm using ION library from Here
The problem I'm having is when I refresh the page, the page itself looks like it is refreshing but the exact same picture is appearing.
I'm assuming its a cached image? If I reinstall the application, then it obtains the correct image again.
This is how I'm using ION where imageID2[position] is just a typical url to a jpg.
Ion.with(imageView)
.placeholder(R.drawable.ic_launcher)
.error(R.drawable.ic_launcher)
.load(imageId2[position]);
Is there anyway I can disable the cache or just make it refind the images again?
Use .noCache() to bypass caches.
As per documentation here, use the "long" way to build an ImageView request so that you can add headers, noCache, etc.
Change your original request from this:
Ion.with(imageView)
.placeholder(R.drawable.ic_launcher)
.error(R.drawable.ic_launcher)
.load(urlString);
To this:
Ion.with(context)
.load(urlString)
.noCache()
.withBitmap()
.placeholder(R.drawable.ic_launcher)
.error(R.drawable.ic_launcher)
.intoImageView(imageView);
You can append a unique string to your url for example a current timestamp in order to force Ion to treat each request as unique.
I have trouble when I'm using Glide in my app. As I've understood, if image was downloaded once and I request image from cache from other activity, Glide must show image quick. And I got this behavior, but not in my app. Image loads very slow (about 3 seconds), although in another app it was about 0.4 second.
My code with calling Glide:
Glide.with(this)
.load(url)
.signature(new StringSignature(url))
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(mHeader);
And in other activity code are same.
May you help me?
Thanks
You don't need the signature(url) part, the model (url String in your case) is already a part of the cache key.
The problem may be that your header changes size. The view size (= resulting Bitmap size) needs to be constant for a cache hit. However since you're doing ALL caching the load should still be fast. Is there anything changing in the url maybe, like a sessionid or similar? That would make the cache miss.
If the url you're loading is an animated GIF RESULT caching can be the culprit, here's a reference.