亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android開(kāi)發(fā)之Picasso通過(guò)URL獲取用戶頭像的圓形顯示

 更新時(shí)間:2022年06月29日 17:04:30   作者:ganchuanpu  
這篇文章主要介紹了android開(kāi)發(fā)之Picasso通過(guò)URL獲取用戶頭像的圓形顯示,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下

1.設(shè)置布局屬性:

<ImageView
 android:scaleType="fitXY"/>

2.BitmapUtils類-- 得到指定圓形的Bitmap對(duì)象

public static Bitmap circleBitmap(Bitmap source) {
 //獲取Bitmap的寬度
 int width = source.getWidth();
 //以Bitmap的寬度值作為新的bitmap的寬高值。
 Bitmap bitmap = Bitmap.createBitmap(width, width, Bitmap.Config.ARGB_8888);
 //以此bitmap為基準(zhǔn),創(chuàng)建一個(gè)畫(huà)布
 Canvas canvas = new Canvas(bitmap);
 Paint paint = new Paint();
 paint.setAntiAlias(true);
 //在畫(huà)布上畫(huà)一個(gè)圓
 canvas.drawCircle(width / 2, width / 2, width / 2, paint);
 //設(shè)置圖片相交情況下的處理方式
 //setXfermode:設(shè)置當(dāng)繪制的圖像出現(xiàn)相交情況時(shí)候的處理方式的,它包含的常用模式有:
 //PorterDuff.Mode.SRC_IN 取兩層圖像交集部分,只顯示上層圖像
 //PorterDuff.Mode.DST_IN 取兩層圖像交集部分,只顯示下層圖像
 paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
 //在畫(huà)布上繪制bitmap
 canvas.drawBitmap(source, 0, 0, paint);
 return bitmap;
}

3.BitmapUtils類--壓縮圖片

//實(shí)現(xiàn)圖片的壓縮處理
//設(shè)置寬高必須使用浮點(diǎn)型,否則導(dǎo)致壓縮的比例:0
public static Bitmap zoom(Bitmap source,float width ,float height){
 Matrix matrix = new Matrix();
 //圖片的壓縮處理
 matrix.postScale(width / source.getWidth(),height / source.getHeight());
 Bitmap bitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, false);
 return bitmap;
}

4.根據(jù)user.getImageurl()顯示圓形圖像

//使用Picasso聯(lián)網(wǎng)獲取圖片
Picasso.with(this.getActivity()).load(user.getImageurl()).transform(new Transformation() {
 @Override
 public Bitmap transform(Bitmap source) {//下載以后的內(nèi)存中的bitmap對(duì)象
  //壓縮處理
  Bitmap bitmap = BitmapUtils.zoom(source, UIUtils.dp2px(62),UIUtils.dp2px(62));
  //圓形處理
  bitmap = BitmapUtils.circleBitmap(bitmap);
  //回收bitmap資源
  source.recycle();
  return bitmap;
 }
 @Override
 public String key() {
  return "";//需要保證返回值不能為null。否則報(bào)錯(cuò)
 }
}).into(ivMeIcon);

以上所述是小編給大家介紹的android開(kāi)發(fā)之Picasso通過(guò)URL獲取用戶頭像的圓形顯示,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論