Images are blurry when rotate the screen android device with Glide - android

I use glide to load the drawable image in the adapter (the error occurred with the image not located in recyclerview):
Glide.with (holder.ivPreview) .load (mThemeDrawableIds.get (position)).into (holder.ivPreview)
When recording mThemeDrawableIds will be reloaded and notify again. However, the image is blurred compared to the original image.
I tried clearing the cache but the result is still the same.

It might help to also add android:adjustViewBounds="true" to your ImageView in XML.
Also try this code :
Glide.with(imageView).load(mThemeDrawableIds.get (position))
.apply(new RequestOptions()
.fitCenter()
.format(DecodeFormat.PREFER_ARGB_8888)
.override(Target.SIZE_ORIGINAL))
.into(holder.ivPreview);

Related

Issue with loading very high resolution (15000 x 8438) image with glide

I am trying to load very high resolution image (15000 x 8438) with glide and saving it as bitmap.
I am using glide for that. The problem is that when I try to save bitmap image to file I get black image instead of actual image.
I feel maybe this is because of very high resolution. After converting to bitmap these values I have obtained: width 15000 height: 8438 getAllocationInBytes : 506280000.
I tried to downscale image with .downsample(DownsampleStrategy.AT_MOST) but image is still 15000 x 8438.
The code I am using is:
Glide.with(this).asBitmap()
.load(imagePath)
.downsample(DownsampleStrategy.AT_MOST)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.into(FileTarget(someFile, Bitmap.CompressFormat.JPEG, 90) {}
Can someone please help, how can I down scale the image and save it to the file. Also is it possible to achieve it with glide ?
Thank you.
To make downsample works as expected, you probably forgot to add the maxWidth and maxHeight override:
....
.downsample(DownsampleStrategy.AT_MOST)
.override(maxWidth, maxHeight)
...

Glide not resize image correctly on Android

I use the bumptech android-glide library to show a bottom banner image on my android application on two different activities. The problem is the main Activity load the image and shows at full size instead of showing centered.
I override the size in both definitions but I can't resize the image on the first Activity. I think the second one is using the cached image loaded by glide but I'm not really sure.
Code of image declared on both layout Activities
<ImageView
android:id="#+id/main_sponsor_banner"
android:layout_width="match_parent"
android:layout_height="50dp"
android:scaleType="centerInside"
android:src="#drawable/default_main_sponsor"/>
Code of glide library on both Activities
ImageView sponsorImage = (ImageView) findViewById(R.id.main_sponsor_banner);
String sponsor_url = "https://static.prosperwalk.com/prosperwalk/organizations/0E79176F-75EB-4096-A1F2-35B886AE24E0/members/FF72A93A-DAB2-4127-ABF2-9417F1F128B7/4D1D86BF-E2A2-4C52-8485-921EDCB7CC99.png";
Glide.with(this)
.load(sponsor_url)
.thumbnail(0.5f)
.crossFade()
.placeholder(R.drawable.default_main_sponsor)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(sponsorImage);
Thanks and any help is appreciated.
Try to use DiskCacheStrategy.SOURCE

How to load GIF image from drawable folder into ImageView using glide?

I have to show load GIF image from drawable to ImageView using glide.I have tried with following.
Glide.with(LoginActivity.this)
.load(getResources().getDrawable(R.drawable.bg_gif)).asGif()
.crossFade()
.into(relativeLayout);
But isn't seem working and it's working when I'm place image in raw folder.but the problem is I have to use different dimension images.
Any help would be greatly appreciated.
You can try to use Ion it works fine for me.
Ion
Using Ion
Ion.with(imgView)
.error(R.drawable.default_image)
.animateGif(AnimateGifMode.ANIMATE)
.load("file:///android_asset/animated.gif");
Using Glide
ImageView imageView = (ImageView) findViewById(R.id.imageView);
GlideDrawableImageViewTarget imageViewTarget = new GlideDrawableImageViewTarget(imageView);
Glide.with(this).load(R.raw.sample_gif).into(imageViewTarget);
Another Approach
For Glide 3.0 you need to set asGif() earlier:
Glide.with(context)
.load(imageUrl)
.asGif()
.placeholder(R.drawable.loading2)
.crossFade()
.into(imageView);
Keep in mind that just using load() will load either a GIF or a Bitmap depending on the type of the data. Unless you want your load to fail if the given url is not a gif, you don't need to specify asGif()
Just pass the resource id directly to load():
Glide.with(LoginActivity.this)
.load(R.drawable.bg_gif)
.asGif() // you may not need this
.crossFade()
.into(relativeLayout);
Steps to load Gif images from drawable
You need to move your Gif image tores/raw folder of your project
(
if your project don't have raw folder in resource directly then simply make one and put your gif in it )
and then you can simply load your gif with just one line of code
Glide.with(this)
.load(R.raw.splash)
.into(new GlideDrawableImageViewTarget(
(ImageView) findViewById(R.id.image)));
Place your Gif in the "raw" folder and use
GlideDrawableImageViewTarget imageViewTarget = new GlideDrawableImageViewTarget(imageView);
Glide.with(this).load(R.raw.test).into(imageViewTarget);
For Glide 4
GlideApp.with(this)
.load(R.raw.gif_file)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.into(imageView);

Picasso center image without resizing into ImageView

I've come across this simple problem with the Picasso library. I haven't find any way to put an image into ImageView center it like android:ScaleType="center" does without cropping. Do you have any ideas about how to solve this ? My problem is that I don't know at the runtime the height and width of the BitMap I download so I can't use resize() properly.
This is a little late, but for anyone who's looking for a solution :
Picasso
.with(context)
.load(ImageURL)
.fit()
// call .centerInside() or .centerCrop() to avoid a stretched image
.into(imageViewFit);
If your ImageView is fixed one dimension and flexible another dimension (ex. android:width="match_parent", android:height="wrap_content"), you should be able to use android:adjustViewBounds="true" to get the ImageView to resize to display your image without cropping.
i am not found fit to center without resizing,
Picasso.get()
.load(source).resize(1650,700)
.centerCrop(Gravity.CENTER).into(imageView, new Callback()

Image transformation not applied after orientation change with Picasso

I am using Picasso and a RoundedTransformation class that applies rounded corners to an image I load with Picasso. Relevant code is below:
Transformation transformation = new RoundedTransformationBuilder()
.cornerRadiusDp(4)
.oval(false)
.build();
ImageView cardViewTop1Image = (ImageView) cardViewTop1.findViewById(R.id.cv_top1_image);
Picasso.with(cardViewTop1.getContext()).load("http:/some_image_url.com")
.fit().centerCrop()
.transform(transformation).into(cardViewTop1Image);
This all works great until I go through two orientation changes - first to horizontal orientation, then back to vertical orientation. When I switch back to vertical orientation, the rounded transformation is no longer applied.
I believe that Picasso is caching the non-transformed image and then filling the ImageView with it. Is there a way I could cache the transformed image or load the non-transformed image from the cache and then apply the transformation? Thanks for the help!
Try this approach to stop caching.
Picasso.with(yourContext)
.load(yourUrl)
.memoryPolicy(MemoryPolicy.NO_CACHE )
.networkPolicy(NetworkPolicy.NO_CACHE)
.fit()
.centerCrop()
.transform(yourTransformation)
.into(yourImageView);
Or try another Transformation. I use this https://gist.github.com/aprock/6213395 .

Categories

Resources