android 圆角图片的实现
生活随笔
收集整理的這篇文章主要介紹了
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 圆角图片的实现的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NSIS 打包.net2.0
- 下一篇: bestcoder #67 div2 1