毕加索如何下载图像
How Picasso downloading images
我对 Picasso
用于下载和缓存图像的机制有疑问。
Picasso
如何下载图片?我知道它在样本量中使用。我对吗?如果服务器上的图像是 1000x1000 但 ImageView
只有 400x400 那么它将只下载 500x500 图像并将被缓存。或者可能会以全分辨率下载,然后缩放到特定大小。
这是我的实际代码 - 我相信还有很多人在使用
Picasso.with(context).load(url).fit().centerCrop().into(imageView);
Picasso 无法知道它应该只下载 500*500 像素。即使图片比需要的大,fit()
和 centercrop()
方法也会使其适合。
您可以浏览 Picasso 的源代码:https://github.com/square/picasso。
正在下载图片
你可以看到 Picasso 下载图片时实现了 Downloader
接口。它使用名为 OkHttpDownloader
的默认下载器,它利用 OkHttp 库。加载不出来的时候,毕加索用UrlConnectionDownloader
。
识别图片大小
Picasso 在下载之前不知道图像的大小。如果您正在开发后端服务器,您可以通过某种方式指定图像的大小,因此您的移动应用程序将通过执行具体请求来了解它,但 Picasso 本身无法识别它。毕加索必须下载完整尺寸的图像,然后该库可以裁剪或调整该图像的大小。
缓存
我们可以在源码中的Picasso文档中找到关于Cache的如下信息:
Picasso instance is automatically initialized with defaults that are
suitable to most implementations.
- LRU memory cache of 15% the available application RAM
- Disk cache of 2% storage space up to 50MB but no less than 5MB. (Note: this is only available on API 14+ or if you are using
a standalone library that provides a disk cache on all API levels like
OkHttp)
- Three download threads for disk and network access.
它很清楚地解释了这个库中缓存的用法。
我只是不确定,毕加索是在转换前(调整大小、裁剪等)还是在缓存中转换后存储图像。第一个选项对我来说似乎更合理,因为我们决定稍后应用不同的转换,所以我们可能希望保留原始图像。
我对 Picasso
用于下载和缓存图像的机制有疑问。
Picasso
如何下载图片?我知道它在样本量中使用。我对吗?如果服务器上的图像是 1000x1000 但 ImageView
只有 400x400 那么它将只下载 500x500 图像并将被缓存。或者可能会以全分辨率下载,然后缩放到特定大小。
这是我的实际代码 - 我相信还有很多人在使用
Picasso.with(context).load(url).fit().centerCrop().into(imageView);
Picasso 无法知道它应该只下载 500*500 像素。即使图片比需要的大,fit()
和 centercrop()
方法也会使其适合。
您可以浏览 Picasso 的源代码:https://github.com/square/picasso。
正在下载图片
你可以看到 Picasso 下载图片时实现了 Downloader
接口。它使用名为 OkHttpDownloader
的默认下载器,它利用 OkHttp 库。加载不出来的时候,毕加索用UrlConnectionDownloader
。
识别图片大小
Picasso 在下载之前不知道图像的大小。如果您正在开发后端服务器,您可以通过某种方式指定图像的大小,因此您的移动应用程序将通过执行具体请求来了解它,但 Picasso 本身无法识别它。毕加索必须下载完整尺寸的图像,然后该库可以裁剪或调整该图像的大小。
缓存
我们可以在源码中的Picasso文档中找到关于Cache的如下信息:
Picasso instance is automatically initialized with defaults that are suitable to most implementations.
- LRU memory cache of 15% the available application RAM
- Disk cache of 2% storage space up to 50MB but no less than 5MB. (Note: this is only available on API 14+ or if you are using a standalone library that provides a disk cache on all API levels like OkHttp)
- Three download threads for disk and network access.
它很清楚地解释了这个库中缓存的用法。 我只是不确定,毕加索是在转换前(调整大小、裁剪等)还是在缓存中转换后存储图像。第一个选项对我来说似乎更合理,因为我们决定稍后应用不同的转换,所以我们可能希望保留原始图像。