怎么在Android中使用毕加索加载网络图片

  介绍

怎么在Android中使用毕加索加载网络图片?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

<强>通过毕加索来缩放

其实毕加索提供了这样的方法。具体是显示转换的转换方法。

(1)先获取网络或本地图片的宽高
(2)获取需要的目标宽
(3)按比例得到目标的高度
(4)按照目标的宽高创建新图

Transformation  Transformation =, new 转换(),{   ,,@Override   ,,,public  Bitmap 变换(Bitmap 源),{   ,,,,int  targetWidth =, mImg.getWidth ();   ,,,,LogCat.i (“source.getHeight ()=? source.getHeight ());   ,LogCat.i (“source.getWidth ()=? source.getWidth ());   ,LogCat.i (“targetWidth=? targetWidth);   ,,,,如果(source.getWidth ()==0) {   ,,,,,return 来源;   ,,,,}   ,,,,//如果图片小于设置的宽度,则返回原图   ,,,,如果(source.getWidth () & lt; targetWidth) {   ,,,,,return 来源;   ,,,,其他}{   ,,,,,//如果图片大小大于等于设置的宽度,则按照设置的宽度比例来缩放   ,,,,,double  aspectRatio =,(双),source.getHeight(),/,(双),source.getWidth ();   ,,,,,int  targetHeight =, (int), (targetWidth  *, aspectRatio);   ,,,,,if  (targetHeight  !=, 0,,,, targetWidth  !=, 0), {   ,,,,,,,Bitmap  result =, Bitmap.createScaledBitmap (targetWidth,来源,还以为,targetHeight,假);   ,,,,,,,if  (result  !=,源),{   ,,,,,,,,,//,Same  bitmap  is  returned  if  sizes 断开连接,从而相同   ,,,,,,,,,source.recycle ();   ,,,,,,,}   ,,,,,,,return 结果;   ,,,,,},{else    ,,,,,,,return 来源;   ,,,,,}   ,,,,}   ,,}   ,,@Override   ,,,public  String 关键(),{   ,,,,,return “transformation", +,“, desiredWidth";   ,,,}   ,,},

之后在毕加索设置变换

Picasso.with (mContext)   ,,,,.load (imageUrl)   ,,,,.placeholder (R.mipmap.zhanwei)   ,,,,. error (R.mipmap.zhanwei)   ,,,,.transform(转换)   ,,,,.into (viewHolder.mImageView);

转换这是毕加索的一个非常强大的功能了,它允许你在负载图片→到ImageView中间这个过成对图片做一系列的变换。比如你要做图片高斯模糊,添加圆角,做度灰处理,圆形图片等等都可以通过转换来完成。

怎么在Android中使用毕加索加载网络图片