日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android 圆角图片的实现

發布時間:2025/7/14 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 圆角图片的实现 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

圖片展示的時候總覺的直角的圖片不好看?好辦法來了!~~

public class ToRoundCorner extends Activity{public Bitmap toRoundCorner(Bitmap bitmap, int pixels) {Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);Canvas canvas = new Canvas(output);final int color = 0xff424242;final Paint paint = new Paint();final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());final RectF rectF = new RectF(rect);final float roundPx = pixels;paint.setAntiAlias(true);canvas.drawARGB(0, 0, 0, 0);paint.setColor(color);canvas.drawRoundRect(rectF, roundPx, roundPx, paint);paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));canvas.drawBitmap(bitmap, rect, rect, paint);return output;}}

把上面的代碼放到工具包中需要的時候只要調用下就好了!

ImageView pic = (ImageView) navigationView.getHeaderView(0).findViewById(R.id.tou_pic);TextView username = (TextView) navigationView.getHeaderView(0).findViewById(R.id.nav_username);TextView phone = (TextView) navigationView.getHeaderView(0).findViewById(R.id.nav_phone);//將圖片轉換成bitmapDrawable drawable = getResources().getDrawable(R.mipmap.aboutus);BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;Bitmap bitmap = bitmapDrawable.getBitmap();//將圖片轉成圓角ToRoundCorner toround = new ToRoundCorner();pic.setImageBitmap(toround.toRoundCorner(bitmap , 50));

用法很簡單是不是? 其中最后一行toround.toRoundCorner(bitmap , 50)中bitmap 是要傳入的圖片,后一個數字越大圖片圓角越明顯。

?

方法摘自:腳本之家(http://www.jb51.net/article/32320.htm)

轉載于:https://www.cnblogs.com/wobeinianqing/p/5076989.html

總結

以上是生活随笔為你收集整理的android 圆角图片的实现的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。