TouchImageView icon indicating copy to clipboard operation
TouchImageView copied to clipboard

Using TouchImageView with Glide library

Open niteshkhatri opened this issue 11 years ago • 17 comments

Hi, when I display the image using Glide library, I can't see the Image. However is I use setImageBitmap() method, the image is perfectly displayedwith all zoom capabilities.

How can I use TouchImageView with Glide library?

niteshkhatri avatar Aug 09 '15 08:08 niteshkhatri

You can try this:

    Glide.with(context).load(url).asBitmap().into(new SimpleTarget<Bitmap>() {
        @Override
        public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
            yourImageView.setImageBitmap(resource);
        }
    });

I can show the images with ViewPager and Glide successfully.

ralphilius avatar Aug 23 '15 15:08 ralphilius

I have an older version of the project which has zoom and pan but without double tap. That loads the images with glide perfectly. But the TouchImageView doesn't load anything when using Glide. I even tried the suggestion made in #112 but that didn't work either. Do note that the way i am loading images using Glide is as below:

Glide.with(getActivity()).load(imageUrl).into(imageView);

And that is working perfectly everywhere else except here.

Bluesir9 avatar Sep 08 '15 12:09 Bluesir9

What @Ralphilius said works - but what if I want to add a .thumbnail() as well using glide.load() inside of that?

eshaanb avatar Sep 25 '15 23:09 eshaanb

I have been having the same issue. It seems to occur only when glide was loading the image over the network, not when it was returned from the cache. I found that the fix mentioned in #112 of adding imageRenderedAtLeastOnce = false; into the setImageBitmap method fixed my problem

lukesleeman avatar Nov 05 '15 04:11 lukesleeman

@Ralphilius solution works for me. However, the image only appear after I pinch the screen a little bit. Someone tell me what's the issue here? How can I debug this?

EDIT: I solved it by setting the initial zoom by 1f

aemxn avatar Dec 03 '15 05:12 aemxn

I know I'm too late for the party but I did some trail/error on this issue and I found a solution.

Instead of loading image as path, i tried to load as File and it worked.

Glide.with(mContext)
                .load(new File(imagePath))
                .placeholder(R.drawable.default_placeholder)
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .skipMemoryCache(false)
                .into(imageview_featured_image);

amarilindra avatar Nov 09 '16 06:11 amarilindra

@Ralphilius' solution works on low resolution images. I wonder if there is a way to handle something like 7000 x 3000 size.

This is how I made it handle large res:

Glide.with(getContext())
                    .load(url)
                    .asBitmap()
                    //.placeholder(R.drawable.default_placeholder)
                    .override(1600, 1600)
                    .into(new BitmapImageViewTarget(imageViewPreview) {
                        @Override
                        public void onResourceReady(Bitmap  drawable, GlideAnimation anim) {
                            super.onResourceReady(drawable, anim);
                            progressBar.setVisibility(View.GONE);
                            imageViewPreview.setImageBitmap(drawable);
                        }
                    });

oliverbob avatar Nov 13 '16 05:11 oliverbob

Thanks to @lukesleeman, that pointed to the solution! I finally fixed it. Image showed only after the first loading. And now it works.

DenisShov avatar Dec 01 '16 18:12 DenisShov

Hey all,

As @lukesleeman said, getting network images through Glide was messing the TouchImageView. Sometimes image didn't load, sometimes they loaded after trying zooming it.

So, before Glide, just setImageResource. Then use Glide normally (thumbnail, placeholder, fade, ...). It works for me @niteshkhatri !

TouchImageView imageToZoom = (TouchImageView) findViewById(R.id.imageView);
imageToZoom.setImageResource(R.drawable.someImage);

Glide.with(getActivity()).load(imageUrl)
                    .thumbnail(0.5f)
                    .placeholder(R.drawable.placeholder)
                    .crossFade()
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .into(imageToZoom );

jeremiasdsa avatar Apr 09 '17 07:04 jeremiasdsa

I've resolved issue as suggested by @aimanbaharum

setting the initial zoom by 1f

waqarul avatar May 29 '17 09:05 waqarul

@Ralphilius What is the solution to load both bitmap and gif?

rakeshvihan avatar Jul 01 '17 04:07 rakeshvihan

Hi there,

Once again, TouchImageView is having some compatibility issues with Glide. The newest stable release of Glide (v4.0.0-RC0) does not seem to properly feed images into TouchImageView irrespective of which of the solutions mentioned on this page I try. @Ralphilius 's solution does work, but loading the image as a bitmap is too slow for the fairly large images that I need to load into TouchImageView. Would anyone have any suggestions for techniques I could try to make this work? Thanks so much!

Laplateau avatar Jul 09 '17 07:07 Laplateau

I have been able to load an Animated Gif into TouchImageView, here is my solution:

 public static void loadGif(String url, final TouchImageView view) {
        L.d("GlideGifTouch url " + url);
        if (isValidUrl(url)) {
            SimpleTarget<GifDrawable> target = new SimpleTarget<GifDrawable>() {
                @Override
                public void onResourceReady(GifDrawable resource, Transition<? super GifDrawable> transition) {
                    resource.start();
                    view.setImageDrawable(resource);
                    view.setZoom(1f);
                }
            };
            GlideApp.with(view.getContext()).asGif().load(url).into(target);
        }
    }

Hope this helps

pizzetto avatar Nov 29 '17 14:11 pizzetto

and my solution is .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)

       glideRequests.load(path)
            .diskCacheStrategy(DiskCacheStrategy.NONE)
            .dontTransform()
            .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
            .transition(withCrossFade())
            .into(imageView); 

gelbertgel avatar Jan 21 '18 16:01 gelbertgel

I had the same issue while loading image from url into TouchImageView using Glide. It would show a black screen. I found a fix which works like this. Pass width and height in Glide override method and after setting bitmap call setzoom of TouchImageView with value 1.

Here is the complete code:

Glide.with(#context)
                        .asBitmap()
                        .load(#url)
                        .apply(new RequestOptions().override(1600, 1600)) //This is important 
                        .into(new BitmapImageViewTarget(#imageview) {
                            @Override
                            public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                                super.onResourceReady(resource, transition);
                                #imageview.setImageBitmap(resource);
                                #imageview.setZoom(1); //This is important
                            }
                        });

ShivamPokhriyal avatar Jul 12 '18 13:07 ShivamPokhriyal

You can try this:

    Glide.with(context).load(url).asBitmap().into(new SimpleTarget<Bitmap>() {
        @Override
        public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
            yourImageView.setImageBitmap(resource);
        }
    });

I can show the images with ViewPager and Glide successfully.

This worked perfectly

Glide.with(context).asBitmap().load(url).into(new SimpleTarget<Bitmap>() {
        @Override
        public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
            // Hide progress bar
            yourImageView.setImageBitmap(resource);
        }
    });

kalyandechiraju avatar Nov 05 '18 12:11 kalyandechiraju

It's 5 years old, so it seems to be irrelevant. If it's still an issue, please reopen it

hannesa2 avatar Mar 25 '19 06:03 hannesa2