在毕加索缩放图像大小 [英] scaling image size in Picasso

查看:135
本文介绍了在毕加索缩放图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一个URL下载图像,并在我的片段的视图显示它。我使用的毕加索这样做,但我想要的图像显示在它的原始宽高比,但比例是一个合理的大小 - 也就是屏幕宽度的75%。我想支持风景和肖像照片。所以,思维是这样的。

I want to download an image from a URL and display it in a View in my fragment. I am using Picasso to do this but I want the image to display in it's original aspect ratio but scaled to be a reasonable size - ie 75% of the screen width. I want to support both landscape and portrait photos. So the thinking is something like this.

如果屏幕宽度为200,图像景观5x4的方面,则图像应显示75%的宽度 - 即150和120的高度(保持比例)

If the screen width is 200 and the image is landscape 5x4 aspect, then the image should be displayed to 75% width - ie 150 and 120 height (keeping proportions)

如果屏幕宽度为200,图像肖像4x5的方面,则图像应显示75%的屏幕宽度,高度尺寸 - 即150的高度和宽度120

If the screen width is 200 and the image is portrait 4x5 aspect, then the image should be display to 75% screen width as the HEIGHT dimension - ie 150 height and 120 width

我怎样才能做到这一点使用毕加索?

How can I do this using Picasso?

推荐答案

突破第一部分向下两个部分:

Breaking the first part down in to two sections:

我要在图像中它的原始宽高比显示

I want the image to display in it's original aspect ratio

要做到这一点,你可以调用.fit()。在毕加索要求centerInside()

To do this you can call .fit().centerInside() on the Picasso request

比例是一个合理的大小 - 也就是屏幕宽度的75%

scaled to be a reasonable size - ie 75% of the screen width

要做到这一点,最简单的方法是在布局指定这一点,所以设置一个ImageView的是这样的宽度。然后,当毕加索将图像加载到该ImageView的它会自动缩放到适合(但保持上述指定的纵横比)。

The easiest way to do this would be to specify this in your layout, so set an ImageView to be this width. Then when Picasso loads the image into this ImageView it will automatically scale it to fit (but keeping the aspect ratio as specified above).

这篇关于在毕加索缩放图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆