Picasso Library: Does Fit() function resize the image? - android

I am currently using the Picasso to load the image file to image view on android. I tried to have an image resized then using fit to fit on the imageView. The fit cannot be used with resize.
Picasso.With().Load().Resize().Fit().Into()
Does the fit function will resize the image.

From the Document of Picasso
Attempt to resize the image to fit exactly into the target ImageView's
bounds. This will result in delayed execution of the request until the
ImageView has been laid out.
So i think the fit function will resize the image.

Related

Can Picasso crop an image without scaling?

I have an image that I'm trying to load with Picasso that I want to crop without scaling.
Is this possible?
For example, if I had:
an image that's 400x800
an image view that's 200x400
Any questions I've seen regarding cropping suggest using resize(x, y).centreCrop(alignGravity) (i.e. scaling and cropping rather than only cropping).
In the example, you'd get the entire image scaled to 50%, as the JavaDocs for centreCrop mentions:
This cropping technique scales the image so that it fills the requested bounds and then crops the extra, preferring the contents at alignGravity.
I want to display the middle 200x400 pixels of the image and lose the edges entirely (similar to how ImageMagick's crop would work).
Is there a way to crop without scaling?
So it seems that out-of-the-box, no it doesn't, but you can use the Picasso Transformations library to do so:
implementation 'jp.wasabeef:picasso-transformations:2.4.0'
and then:
Picasso.get()
.load(largeImage)
.transform(new CropTransformation(width, height, GravityVertical.CENTER, GravityVertical.CENTER))
.into(imageView, /* callback */);
If you are using resize() or centreCrop() you need to use after the call to transform().

How to preload imageView's height and width attribute?

When using a recycleView with many images, Glide takes a while to load the image for the first time, how can I preload the image's height and width by setting the imageView to that size before using glide to load it in?
Glide.with(mContext)
.load(link)
.apply(RequestOptions.centerInsideTransform())
.into(holder.vhImageView);
Reddit also does it this way
Glide may have an equivalent method, but I use Picasso, and you can set a .placeHolder(R.drawable.placeholder) image that will be in place until the image actually loads.
You could assign holder.vhImageView a default image in xml that should also work as a placeholder as long as Glide doesn't clear it as it's loading the new image?
You could set a minHeight on the holder.vhImageView in XML but that can cause problems if the views loaded end up being shorter than that.

Scale ImageView to fit without stretching

How can i fit the ImageView without stretching? I've already tried all 'scaleType' but no one works. this image is from instagram API.
When i use 'Matrix' scaleType.
Depends which side you want to fit.
You can resize bitmap if you need some custom fit.
You can use 'scaleType' centerCrop to fill all ImageView.
P.S. but if you want to make rectangle picture from square one, without losing some part of picture - you have no chance, it is impossible anyway.
Maybe it is better for you to resize ImageView to fit image ratio.

Display images with proper dimensions before loading using glide and recyclerview

How do I display images in a facebook like feed? So far I've been using match_parent for width and wrap_content or fixed height. This works well but I need to show proper blank space for image feeds while it's getting lazy loaded. Like how do I set the dimensions properly for the image before loading it from the internet.
I think about getting the aspect ratio or the image dimensions itself via the api. Is it the only correct way or is there some other better way to achieve it using glide or any image loading library?
If you are using glide, you can set a place holder image or drawable with the dimensions you need while the real image is being downloaded.
Glide
.with(context)
.load(UsageExampleListViewAdapter.eatFoodyImages[0])
.placeholder(R.mipmap.ic_launcher) // can also be a drawable
.into(imageViewPlaceholder);

How to resize ImageView placeholder with picasso

Picasso allows me to resize an image. Is there a mechanism for resizing the placeholder? The following is not sufficient. What am I missing?
Picasso.with(mContext).load(url).placeholder(R.drawable.imageview_holder).resize(200, 200).into(imageview);
What I found that works for me is to resize the placeholder (and error image) directly with the ImageView using android:scaleType="fitCenter" in the XML. Then I can still use Picasso to resize and center the downloaded image.

Categories

Resources