Using TouchImageView with Glide library
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?
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.
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.
What @Ralphilius said works - but what if I want to add a .thumbnail() as well using glide.load() inside of that?
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
@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
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);
@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);
}
});
Thanks to @lukesleeman, that pointed to the solution! I finally fixed it. Image showed only after the first loading. And now it works.
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 );
I've resolved issue as suggested by @aimanbaharum
setting the initial zoom by 1f
@Ralphilius What is the solution to load both bitmap and gif?
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!
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
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);
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
}
});
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);
}
});
It's 5 years old, so it seems to be irrelevant. If it's still an issue, please reopen it