Picasso center image without resizing into ImageView - android

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

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 into(Target) OOM

I am using Glide frame to load a picture, I want to set the height and the width of it, and I know what is the width I want, but how can I set the height of it.
what I have tried is blow,and I got an error of OOM. waiting for help, thanks.
if you want change size
Glide
.with(context)
.load(UsageExampleListViewAdapter.eatFoodyImages[0])
.override(600, 200) // resizes the image to these dimensions (in pixel). does not respect aspect ratio
.into(imageViewResize);
Reference
Using override method of glide you can set the dimension of image in pixels.
Glide
.with(context)
.load(url)
.override(50 , 50)
.into(imageview);

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

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 .

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