我是靠谱客的博主 神勇向日葵,这篇文章主要介绍Android 使用Picasso加载网络图片等比例缩放,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Transformation transformation = new Transformation() { @Override public Bitmap transform(Bitmap source) { int targetWidth = imageview.getWidth(); if (source.getWidth() == 0) { return source; } //如果图片大小大于等于设置的宽度,则按照设置的宽度比例来缩放 double aspectRatio = (double) source.getHeight() / (double) source.getWidth(); int targetHeight = (int) (targetWidth * aspectRatio); if (targetHeight != 0 && targetWidth != 0) { Bitmap result = Bitmap.createScaledBitmap(source, targetWidth, targetHeight, false); if (result != source) { // Same bitmap is returned if sizes are the same source.recycle(); } return result; } else { return source; } } @Override public String key() { return "transformation" + " desiredWidth"; } };
复制代码
1
2
3
4
5
Picasso .load(serviceInShopPageListBean .getServiceDownUrl()) .transform(transformation) .into(imageview);

最后

以上就是神勇向日葵最近收集整理的关于Android 使用Picasso加载网络图片等比例缩放的全部内容,更多相关Android内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(63)

评论列表共有 0 条评论

立即
投稿
返回
顶部