glide-support
glide-support copied to clipboard
help me!RegionImageVideoDecoder RegionFileDecoder Cannot cache Rect in image
Hello, I have implemented long image loading with reference to your image block, but since the glide.load(file) key is unique, it is impossible to cache the image created by Rect. Please help me.
glide.load(file)
.asBitmap()
.decoder(new RegionImageVideoDecoder(MyApplication.getInstance(), rect,simpleSize))
.cacheDecoder(new RegionFileDecoder(MyApplication.getInstance(), rect,simpleSize))
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation<? super Bitmap> glideAnimation) {
weakReference=new WeakReference<>(bitmap);
if(runable!=null){
runable.run();
}
isLoading=false;
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
super.onLoadFailed(e, errorDrawable);
isLoading=false;
}
});
Hey, here's the full example with some links: https://github.com/TWiStErRob/glide-support/blob/master/src/glide3/java/com/bumptech/glide/supportapp/github/_700_tall_image/ImageChunkAdapter.java#L113
The approach is that the original large images is saved to disk cache (SOURCE) and then pieces will be decoded from that single file, but not cached. When I wrote this bumptech/glide#707 was preventing caching those images.
If this problem didn't exist we could be using signature to cache the result.
If you really need to cache the cropped bits, I suggest you download the image (which you seem to have done), and use that as the source (as opposed to my example where the input is still the URL and the File lookup will be done by Glide). This way you can use a RESULT cache and use a signature with file,x,y,w,h composition to key the individual bits.
Hello, may I ask how the specific code should be written
How can I cache each of the decoded pictures?
Here are the steps I think are enough to make it work:
- download the file either via Glide cache or external, so you have the large image as a
File - use
.decoder(RegionFileDecoder) - add signature for caching the rectangle
all the pieces are there in the example code, just need to move a few things around.