glide-support icon indicating copy to clipboard operation
glide-support copied to clipboard

help me!RegionImageVideoDecoder RegionFileDecoder Cannot cache Rect in image

Open chongbo2013 opened this issue 6 years ago • 5 comments

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;

                    }
                });

chongbo2013 avatar Dec 14 '18 12:12 chongbo2013

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.

TWiStErRob avatar Dec 14 '18 14:12 TWiStErRob

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.

TWiStErRob avatar Dec 14 '18 14:12 TWiStErRob

Hello, may I ask how the specific code should be written

chongbo2013 avatar Dec 14 '18 16:12 chongbo2013

How can I cache each of the decoded pictures?

chongbo2013 avatar Dec 14 '18 16:12 chongbo2013

Here are the steps I think are enough to make it work:

  1. download the file either via Glide cache or external, so you have the large image as a File
  2. use .decoder(RegionFileDecoder)
  3. add signature for caching the rectangle

all the pieces are there in the example code, just need to move a few things around.

TWiStErRob avatar Dec 20 '18 11:12 TWiStErRob