Download pictures appear incomplete
Sometimes download pictures appear incomplete Code is the latest
Do you use okhttp or volley?
How do yo load the image?
Do you have transformations?
What is your target (.into())?
Latest=3.5.2 or latest=3.6.0-SNAPSHOT?
Is there an exception in LogCat? Is onException of .listener() called?
use okhttp
ivHd.getLayoutParams().width = Device.getWidth();
ivHd.getLayoutParams().height = Device.getWidth()*15/32;
Glide.with(WeiBoListNewActivity.this, null).load(hd.ImageUrl).placeholder(R.color.guidColor).error(R.color.guidColor)
.override(Device.getWidth(), Device.getWidth()*15/32)
.crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).centerCrop()
.transform(new BitmapTransformation(WeiBoListNewActivity.this) {
@Override
public String getId() {
return Device.getMD5String(hd.ImageUrl);
}
@Override
protected Bitmap transform(BitmapPool arg0, Bitmap source, int arg2, int arg3) {
x = source.getWidth();
y = source.getHeight();
return source;
}
})
.listener(new RequestListener<Object, GlideDrawable>() {
@Override
public boolean onException(Exception arg0, Object arg1,
Target<GlideDrawable> arg2, boolean arg3) {
return false;
}
@Override
public boolean onResourceReady(GlideDrawable arg0, Object arg1,
Target<GlideDrawable> arg2, boolean arg3, boolean arg4) {
if(x >0 && y>0) {
setXY(x, y);
LinearLayout.LayoutParams a = new LinearLayout.LayoutParams(Device.getWidth(), Device.getWidth()*y/x);
ivHd.setLayoutParams(a);
Glide.with(WeiBoListNewActivity.this, null).load(hd.ImageUrl).placeholder(R.color.guidColor).error(R.color.guidColor)
.override(Device.getWidth(), Device.getWidth()*y/x)
.crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).centerCrop()
.into(ivHd);
} else {
int x1 = 32, y1 = 15;
if(getX()>0 && getY()>0) {
x1 = getX();
y1 = getY();
}
ivHd.getLayoutParams().width = Device.getWidth();
ivHd.getLayoutParams().height = Device.getWidth()*y1/x1;
Glide.with(WeiBoListNewActivity.this, null).load(hd.ImageUrl).placeholder(R.color.guidColor).error(R.color.guidColor)
.override(Device.getWidth(), Device.getWidth()*y1/x1)
.crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE).centerCrop()
.into(ivHd);
}
return true;
}
})
.into(ivHd);
The probability is very small Images are downloaded successfully, but I think it is not a complete picture downloaded only by the above method I use to appear, if I'm not inside the listener implementation will have no problems
and I use the latest code
Sounds like #419 :)
Can you check your logcat and search for : skia﹕ ---- read threw an exception or skia﹕ --- decoder->decode returned false
Yup, sounds like a duplicate of #419, if not, feel free to reopen.
Ok looking through #419, these seem like they're probably different issues. Can you follow @TWiStErRob and @Tolriq's advice and look for stack traces?
Even if the app doesn't crash, there's probably a stack trace of an error somewhere in your adb logs.
I saw you give the solution, but there is no specific solutions or examples
@liaibai I don't think we found any general problem in the other issue. Can you provide stack traces, or error messages? Or maybe a sample app that reproduces the problem?
He sent me a zipped project to my email, his comments were:
When I was in the ListActivity, will appear to slide back and forth fast image loading is incomplete
Glide.with(ListActivity.this).load(urls.get(position)) .placeholder(R.color.white1).crossFade(0) .override(Device.getWidth()/2, Device.getWidth()*9/ 32) .error(R.color.black) .diskCacheStrategy(DiskCacheStrategy.SOURCE) .centerCrop().into(holder.iv);When I used ‘DiskCacheStrategy.SOURCE ’ time, the picture will be incomplete but When I used ‘DiskCacheStrategy.RESULT ’ time , Image must be complete
He also sent me screenshots which show a partially loaded image in a listview.
I analyzed the above and found the following:
- I couldn't reproduce the bug he mentions.
- He is using a downloaded version of the github repo, not an "official" distribution at 6c85b134d797126469dc3ab1a719e9edcf155573
- He hacked his own cache wrapper which reads and writes bare files into
DiskLruCacheWrapper
This was probably done because disklrucache source is not packaged into the zip downloaded from GitHub, I'll send him the version with jars and unhacked :) - Based on his description I was attacking Glide with the following script to no avail. My suspicion was that it's related to timeouts because the servers are slow, but maybe it's just because I'm in Europe.
<?php
// return a normal jpeg image cut in half (bytes)
// emulate different combination of content-length, partial content, and timeouts
header('Content-Type: image/jpeg');
$file1 = 'big.001';
$file2 = 'big.002';
$f1 = filesize($file1);
$f2 = filesize($file2);
//header('Content-Length: '. ($f1+$f2));
readfile($file1);
//sleep(2);
readfile($file2);
exit;
?>
Loading it like this:
Glide.setup(new GlideBuilder(this).setBitmapPool(new BitmapPoolAdapter())); // no reuse
Glide.get(getApplicationContext()).clearDiskCache(); // so source is always refilled
Glide
.with(getApplicationContext())
.load("http://192.168.0.2/jpeg.php")
.placeholder(android.R.color.holo_purple)
.error(android.R.color.black)
.skipMemoryCache(true) // no reuse
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.into(imageView);
Thanks for following up @TWiStErRob, it's totally plausible there's some issue with timeouts we don't handle. However we make a fairly substantial effort to ignore decoded images when we detect either an exception or that we've failed to read the expected number of bytes. Maybe there's a case I haven't thought of.
I'm going to close this for now, I'll keep an eye out of this in the future and hopefully we can figure out what we're missing here...
Sorry this got lost in my inbox. Still no repro though.
I modified his project to remove hacking Glide/Diskwrapper and after that:
I use your local cache mode there is no problem, but when I use my local cache will appear before the picture is not complete, why? Now I think it is not a cache problem, but the problem is displayed, complete the picture is downloaded, but the display is not complete With my own local storage method, I use your example, I found pictures downloaded are complete, some display picture is incomplete,
He's on Android 5.0.1. I couldn't repro it on Galaxy S4 4.4.2.
And then he sent me a video and the cache contents. The cache contents were intact, the jpeg files were all complete on the file system, but the images displayed were partial (bottom part missing) in the video.