Android應(yīng)用中繪制圓形頭像的方法解析
要畫這種圓形帶陰影的頭像,個人分解成三個圖層
1,先畫頭像邊緣的漸變
RadialGradient gradient = new RadialGradient(j/2,k/2,j/2,new int[]{0xff5d5d5d,0xff5d5d5d,0x00ffffff},new float[]{0.f,0.8f,1.0f}, Shader.TileMode.CLAMP); paint.setShader(gradient); canvas.drawCircle(j/2,k/2,j/2,paint);
2,截去出圓形頭像Bitmap
/** * 轉(zhuǎn)換圖片成圓形 * @param bitmap 傳入Bitmap對象 * @return */ public Bitmap toRoundBitmap(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); float roundPx; float left,top,right,bottom,dst_left,dst_top,dst_right,dst_bottom; if (width <= height) { roundPx = width / 2 -5; top = 0; bottom = width; left = 0; right = width; height = width; dst_left = 0; dst_top = 0; dst_right = width; dst_bottom = width; } else { roundPx = height / 2 -5; float clip = (width - height) / 2; left = clip; right = width - clip; top = 0; bottom = height; width = height; dst_left = 0; dst_top = 0; dst_right = height; dst_bottom = height; } Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect src = new Rect((int)left, (int)top, (int)right, (int)bottom); final Rect dst = new Rect((int)dst_left, (int)dst_top, (int)dst_right, (int)dst_bottom); final RectF rectF = new RectF(dst_left+15, dst_top+15, dst_right-20, dst_bottom-20); 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, src, dst, paint); return output; }
3,最后畫上白邊
Paint paint = new Paint(); paint.setColor(0xffffffff); paint.setStrokeWidth(10); paint.setStyle(Paint.Style.STROKE); canvas.drawCircle(j/2,k/2,j/2-20,paint);
PS:Android App常用圖標(biāo)尺寸規(guī)范
1. 程序啟動圖標(biāo):
LDPI (Low Density Screen,120 DPI),其圖標(biāo)大小為 36 x 36 px。
MDPI (Medium Density Screen, 160 DPI),其圖標(biāo)大小為 48 x 48 px。
HDPI (High Density Screen, 240 DPI),其圖標(biāo)大小為 72 x 72 px。
xhdpi (Extra-high density screen, 320 DPI),其圖標(biāo)大小為 96 x 96 px。
xxhdpi(xx-high density screen, 480 DPI),其圖標(biāo)大小為144 x 144 px。
2.底部菜單圖標(biāo)
(1)大屏:
完整圖片(紅色): 72 x 72 px
圖標(biāo)(藍(lán)色): 48 x 48 px
圖標(biāo)外邊框(粉色): 44 x 44 px
(2)中屏:
完整圖片: 48 x 48 px
圖標(biāo): 32 x 32 px
圖標(biāo)外邊框: 30 x 30 px
(3)小屏:
完整圖片: 36 x 36 px
圖標(biāo): 24 x 24 px
圖標(biāo)外邊框: 22 x 22 px
3. 彈出對話框頂部圖標(biāo)
小屏 24 x 24 px Low density screen (ldpi)
中屏 32 x 32 px Medium density screen (mdpi)
大屏 48 x 48 px High density screen (hdpi)
4. 長列表內(nèi)部列表項(xiàng)圖標(biāo)
小屏 24 x 24 px Low density screen (ldpi)
中屏 32 x 32 px Medium density screen (mdpi)
大屏 48 x 48 px High density screen (hdpi)
5. 底部或頂部tab標(biāo)簽圖標(biāo)
(1)大屏 (hdpi) screens:
完整圖片(紅色): 48 x 48 px
圖標(biāo)(藍(lán)色): 42 x 42 px
(2)中屏 (mdpi) screens:
完整圖片: 32 x 32 px
圖標(biāo): 28 x 28 px
(3)小屏(ldpi) screens:
完整圖片: 24 x 24 px
圖標(biāo): 22 x 22 px
6. 底部狀態(tài)欄圖標(biāo)
ldpi (120 dpi) 18 x 18 px 小屏
mdpi (160 dpi) 24 x 24 px 中屏
hdpi (240 dpi) 36 x 36 px 大屏
xhdpi (320 dpi) 48 x 48 px 特大屏
- Android一行代碼實(shí)現(xiàn)圓形頭像
- Android仿QQ圓形頭像個性名片
- Android 自定義圓形頭像CircleImageView支持加載網(wǎng)絡(luò)圖片的實(shí)現(xiàn)代碼
- Android利用CircleImageView實(shí)現(xiàn)圓形頭像的方法
- Android自定義控件仿QQ編輯和選取圓形頭像
- 利用Android中BitmapShader制作自帶邊框的圓形頭像
- Android使用CircleImageView實(shí)現(xiàn)圓形頭像的方法
- Android中使用CircleImageView和Cardview制作圓形頭像的方法
- Android實(shí)現(xiàn)本地上傳圖片并設(shè)置為圓形頭像
- Android Studio實(shí)現(xiàn)帶邊框的圓形頭像
相關(guān)文章
android實(shí)現(xiàn)點(diǎn)擊圖片全屏展示效果
這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)點(diǎn)擊圖片全屏展示效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-08-08在RecyclerView中實(shí)現(xiàn)button的跳轉(zhuǎn)功能
本次實(shí)驗(yàn)就是在RecyclerView中添加一個button控件并實(shí)現(xiàn)監(jiān)聽,使鼠標(biāo)點(diǎn)擊時可以跳轉(zhuǎn)到另外一個設(shè)計(jì)好的界面,對RecyclerView實(shí)現(xiàn)button跳轉(zhuǎn)功能感興趣的朋友一起看看吧2021-10-10flutter?Bloc?add兩次只響應(yīng)一次問題解析
這篇文章主要為大家介紹了flutter?Bloc?add兩次只響應(yīng)一次問題解析記錄,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11淺談Android應(yīng)用的內(nèi)存優(yōu)化及Handler的內(nèi)存泄漏問題
這篇文章主要介紹了Android應(yīng)用的內(nèi)存優(yōu)化及Handler的內(nèi)存泄漏問題,文中對Activity無法被回收而造成的內(nèi)存泄漏給出了通常的解決方案,需要的朋友可以參考下2016-02-02