How to create center cropped thumbnail images from image url in android - android

I am using glide library for loading my images , i am showing entire images , i want to show thumbnail image. How to do it?
Glide.with(context)
.load(resized)
.centerCrop()
.placeholder(R.drawable.default_review)
.crossFade().fitCenter()
.into(triviaImage);
I have tried scaleType:fitXY and scaleType:centerCrop nothing worked.
please see image

You should have to use override(width, height) as shown here:
Glide.with(context)
.load(resized)
.asBitmap()
.override(400, 400) // smaller the size, lower the quality of Image
.centerCrop()
.error(R.drawable.image_error_placeholder)
.into(triviaImage);

try this,
Glide
.with( context )
.load( resized )
.thumbnail( 0.1f )
.into( triviaImage);

I fix my problem by this -
Glide.with(context)
.load(myImageUrl)
/*Here "myImageUrl" is the original image url*/
.thumbnail(Glide.with(context).load(myThumbImageUrl).centerCrop())
/*Here "myThumbImageUrl" is the thumb image url*/
.into(view);

Related

How to load gif image url with Glide?

I can load a gif image url, but not able to load with Glide using this code.
Glide.with(context)
.load("gif imageurl")
.asGif()
.crossFade()
.into(imageview);
How to load a gif image from server using Glide?
You can try this approach:
Glide.with(context)
.load(R.raw.sample_gif)
.into(new GlideDrawableImageViewTarget(yourImageView))
or so, try to move the call of the method asGif before the loading
Glide.with(context)
.asGif()
.load("gif image url")
.crossFade()
.into(imageview);
You can try this below code:
ImageView gif = (ImageView) findViewById(R.id.gif);
Glide.with(this)
.asGif()
.load("gif image url")
.into(gif);
You can try on this way it's work fine.
ImageView im_gif = (ImageView) findViewById(R.id.im_gif);
Glide.with(this).asGif().load(R.raw.gif_logo).into(im_gif);
You can add your gif image file to resource/raw folder.and set that name into load method.

Is it possible to show GIF and also JPG image on the same adapter using Glide?

Is it possible to show GIF and also JPG image on the same adapter using Glide? If it is possible, then how code looks like in Glide?
You can do like this
String str = "image or gif url";
if (str.contains(".gif")){
Glide.with(this)
.asGif()
.load(str)
.into(imgeview);
}else{
Glide
.with(this)
.load(str)
.centerCrop()
.into(myImageView);
}

how to get the bitmap cached through Glide?

I am using Glide library for displaying image from url in recyclerView ,
Glide.with( context )
.load(url).placeholder(R.drawable.default_user_picture)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.crossFade()
.into(iv);
but since I want to print the bitmap from my app , I also want to get the bitmap of the image cached by Glide, so How to get the bitmap if we specify the url of the image that is already Cached?

Android Glide download before display

I'm using Glide and I want to know if it's possible to download all images without display them to fill the cache to display them later ? I tried this but the images are not downloaded :
for (String url: urls) {
Glide.with(getBaseContext()).load(url);
Log.v("Download", "processing");
}
Can you help me ?
I solved my problem we can use this to download the images :
Glide
.with( context )
.load( "http://futurestud.io/icon.png" )
.downloadOnly(2000, 2000);
And to get and display the images in the cache, we should use the same url and add the diskCacheStrategy parameter like this :
Glide.with(context)
.load( "http://futurestud.io/icon.png" )
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(imageView);
You can use asBitmap method in Glide to do the same.
Glide.with(this).
load(url).
asBitmap().
into(100, 100). // Width and height
get();
Glide version 4.6.1
RequestOptions requestOptions = new RequestOptions().priority(Priority.IMMEDIATE);
Glide.with(appContext)
.download(model)
.apply(requestOptions)
.submit();

Captcha image cannot be refresh by using Glide

I have tried to use Glide to load an Captcha image into a ImageView. The first time loading is fine. However, when I reload the Captcha image into the same ImageView, the ImageView does not refresh to new image. Does anyone have idea how to solve this issue?
String url = "https://captcha_path";
ImageView imgView = (ImageView)getActivity().findViewById(R.id.imgView);
Glide.with(getActivity()).load(url).asBitmap().diskCacheStrategy(DiskCacheStrategy.NONE).into(imgView);
You can always use Glide.clear() and then call Glide.with(...).load() again. If your url doesn't change when the image changes, you may also need to add .skipMemoryCache(true) to your load call. For more control, check out the .signature() API. You can always do something like:
Glide.with(fragment)
.load(url)
.signature(new StringSignature(UUID.randomUUID().toString()))
.into(imgView);
Glide.with(fragment)
.load(url)
.signature(new StringSignature(UUID.randomUUID().toString()))
.into(imgView);
Replace StringSignature with ObjectKey (for Glide v4)
Glide.with(fragment)
.load(url)
.signature(new ObjectKey(UUID.randomUUID().toString()))
.into(imgView);

Categories

Resources