Glide not resize image correctly on Android - 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

Related

Images are blurry when rotate the screen android device with Glide

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

Android Glide ImageView ScaleType Matrix Centering

I'm using Glide 4.0 to load an image into an ImageView with scaleType="matrix" for pan and zoom functionality. The image does not load centered. If it is tall it loads to the left and if it is wide it loads at the top (see pictured). I've tried the various RequestOptions but none will center the image initially. How can I accomplish this? Thanks!
Current Tall or Wide Image Position
Activity
Uri selectedImage = returnedIntent.getData();
RequestOptions options = new RequestOptions().fitCenter();
Glide.with(MyActivity.this).load(selectedImage).apply(options).into(mImage);
Layout
<ImageView
android:id="#+id/m_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="matrix" />
you are overriding the functionality of scaleType attribute by using .apply(options)
only remove it so the request will be
Glide.with(MyActivity.this).load(selectedImage).into(mImage);
you may find this link helpful
https://github.com/wasabeef/glide-transformations/issues/94

Displaying an image from within an Android app?

I have filepath which is a String holding the absolute path to an image file.
Is there a way to display the image to the user similar to when they use the Gallery app?
When I looked up solutions to this problem, most of them involved setting an ImageView's bitmap to the bitmap decoded from the file, but I don't want to go this route because the orientations may be different, the size of the picture may not be maximized depending on how it fits within the ImageView, and so on. I basically want to have it displayed full-screen. Or if this can be done with an ImageView I'd be curious to know how.
Is this possible to do?
You can declare an ImageView in your layout that fills the parent
<ImageView
android:layout_gravity="fill"
android:id="#+id/your_image"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
Then you use the Picasso library to load the image by
1/ Inflating the ImageView
yourImage = (ImageView) view.findViewById(R.id.your_image);
2/ Loading the image to the ImageView like
Picasso.with(context).load(filepath).fit().into(yourImage);
Check http://square.github.io/picasso/
Use the following library: TouchImageView
Usage:
Place TouchImageView.java in your project. It can then be used the same as
ImageView. Example:
TouchImageView img = (TouchImageView) findViewById(R.id.img);
If you are using TouchImageView in xml, then you must provide the full package
name, because it is a custom view. Example:
<com.example.touch.TouchImageView
android:id="#+id/img"
android:layout_width="match_parent"
android:layout_height="match_parent" />

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

Images are not clear - Picasso Android

I'm using Picasso for downloading images from URL and putting in ImageView. Images are rectangle, but my ImageViews are squares. So I need to use some cropping, because I have spaces on top and bottom.
Without cropping the image is clear:
Picasso.with(context)
.load(left.get(pos).getImageName())
.into(ivFrontPageLeftImage);
To fit inside and crop I'm using:
Picasso.with(context)
.load(left.get(pos)
.getImageName())
.fit().centerInside()
.into(ivFrontPageLeftImage);
But as you can see the image is not clear, it is blur.
So how can I fit image inside the square (ImageView). Also image need to be clear, not blur?
I download this image, crop it with size 300 x 300 (to be square, i cut from left and right) and upload it. I use this new image to put in ImageView:
Picasso.with(context)
.load("http://oi62.tinypic.com/29y61p3.jpg")
.fit().centerCrop()
.into(ivFrontPageLeftImage);
As you can see image is clear and it is not blur.
How can I do this programmatically? Is it possible with Picasso, or I need other library to do this?
I can't comment on Lee's answer as I don't have enough reputation. But his answer was correct as I had the same issue. You can also set it in the ImageView object by doing the following:
imageView = (ImageView) view.findViewById(R.id.img);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
Apply center crop on your ImageView instead of the method you are now using.
<ImageView
...
android:scaleType="centerCrop"/>

Categories

Resources