Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using TouchImageView with Glide library #135

Closed
niteshkhatri opened this issue Aug 9, 2015 · 17 comments
Closed

Using TouchImageView with Glide library #135

niteshkhatri opened this issue Aug 9, 2015 · 17 comments

Comments

@niteshkhatri
Copy link

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?

@ralphilius
Copy link

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.

@Bluesir9
Copy link

Bluesir9 commented Sep 8, 2015

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.

@eshaanb
Copy link

eshaanb commented Sep 25, 2015

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

@lukesleeman
Copy link

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

@aemxn
Copy link

aemxn commented Dec 3, 2015

@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

@amarilindra
Copy link

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);

@oliverbob
Copy link

oliverbob commented Nov 13, 2016

@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);
                        }
                    });

@DenisShov
Copy link

DenisShov commented Dec 1, 2016

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

@jeremiasdsa
Copy link

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 );

@waqarul
Copy link

waqarul commented May 29, 2017

I've resolved issue as suggested by @aimanbaharum

setting the initial zoom by 1f

@rakeshvihan
Copy link

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

@Laplateau
Copy link

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!

@pizzetto
Copy link

pizzetto commented Nov 29, 2017

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

@gelbertgel
Copy link

gelbertgel commented Jan 21, 2018

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); 

@ShivamPokhriyal
Copy link

ShivamPokhriyal commented Jul 12, 2018

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
                            }
                        });

@kalyandechiraju
Copy link

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);
        }
    });

@hannesa2
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests