Android 實現(xiàn)切圓圖作為頭像使用實例
更新時間:2016年12月25日 10:48:47 投稿:lqh
這篇文章主要介紹了Android 實現(xiàn)切圓圖作為頭像使用實例的相關資料,需要的朋友可以參考下
Android 切圓圖
效果圖如下:
MyView 類
public class MyView extends View { Bitmap bmp; Paint paint = new Paint(); public MyView(Context context) { super(context); } public MyView(Context context, AttributeSet attrs) { super(context, attrs); bmp = BitmapFactory.decodeResource(getResources(), R.mipmap.c); src = new RectF(bmp.getWidth() / 2 - 50, bmp.getHeight() / 2 - 50, bmp.getWidth() / 2 + 50, bmp.getHeight() / 2 + 50); dst = new Rect(200, 200, 400, 400); paint.setAntiAlias(true); paint.setDither(true); Shader shaer = new BitmapShader(bmp, Shader.TileMode.MIRROR, Shader.TileMode.REPEAT); paint.setShader(shaer); } private RectF src = null; private Rect dst = null; @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); //繪制Bitmap Matrix m = new Matrix(); //每次set都會重置矩形 m.setRotate(90, bmp.getWidth() / 2, bmp.getHeight() / 2); m.postTranslate(100, 100); m.preScale(0.5f, 0.5f, bmp.getWidth() / 2, bmp.getHeight() / 2); //錯切 m.postSkew(0.3f, 0.3f); // canvas.drawBitmap(bmp, m, null); // canvas.drawBitmap(bmp, src, dst, null); //拿view的高寬 canvas.drawArc(src, 100, 270, true, paint); } }
MainActivity 類
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }
xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.administrator.lesson12_drawbitmap.MainActivity"> <com.example.administrator.lesson12_drawbitmap.MyView android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
您可能感興趣的文章:
- Android自定義view實現(xiàn)圓形、圓角和橢圓圖片(BitmapShader圖形渲染)
- Android基礎之使用Fragment控制切換多個頁面
- android客戶端從服務器端獲取json數(shù)據(jù)并解析的實現(xiàn)代碼
- Android 動畫之ScaleAnimation應用詳解
- android調(diào)試工具DDMS的使用詳解
- Android按鈕單擊事件的四種常用寫法總結
- Android的Activity跳轉動畫各種效果整理
- Android SQLite數(shù)據(jù)庫增刪改查操作的使用詳解
- Android 動畫之RotateAnimation應用詳解
- Android基礎之Fragment與Activity交互詳解
- Android開發(fā)之SQLite的使用方法
- Android中判斷網(wǎng)絡連接是否可用及監(jiān)控網(wǎng)絡狀態(tài)
- 解析android中ProgressBar的用法
- android 調(diào)用系統(tǒng)的照相機和圖庫實例詳解
相關文章
Android調(diào)用系統(tǒng)圖庫獲取圖片的方法
這篇文章主要為大家詳細介紹了Android調(diào)用系統(tǒng)圖庫獲取圖片,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-08-08kotlin android extensions 插件實現(xiàn)示例詳解
這篇文章主要為大家介紹了kotlin android extensions 插件實現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-10-10Android Studio修改Log信息顏色的實現(xiàn)
這篇文章主要介紹了Android Studio修改Log信息顏色的實現(xiàn),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-04-04Android開源框架的SlidingFragment的使用示例
今天小編就為大家分享一篇關于Android開源框架的SlidingFragment的使用示例,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-03-03Flexbox+ReclyclerView實現(xiàn)流式布局
這篇文章主要為大家詳細介紹了Flexbox+ReclyclerView實現(xiàn)流式布局,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-11-11Android編程之SMS讀取短信并保存到SQLite的方法
這篇文章主要介紹了Android編程之SMS讀取短信并保存到SQLite的方法,涉及Android針對SMS短信及SQLite數(shù)據(jù)庫的相關操作技巧,需要的朋友可以參考下2015-11-11實例講解Android app開發(fā)中ListView的基本使用及優(yōu)化
這篇文章主要介紹了Android app開發(fā)中ListView的基本使用及優(yōu)化,ListView視圖組件是Android中最常用的組件之一需要的朋友可以參考下2016-02-02