欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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調(diào)用系統(tǒng)圖庫獲取圖片的方法

    Android調(diào)用系統(tǒng)圖庫獲取圖片的方法

    這篇文章主要為大家詳細介紹了Android調(diào)用系統(tǒng)圖庫獲取圖片,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • Android動態(tài)布局使用詳解

    Android動態(tài)布局使用詳解

    這篇文章主要為大家詳細介紹了Android動態(tài)布局的使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-07-07
  • kotlin android extensions 插件實現(xiàn)示例詳解

    kotlin android extensions 插件實現(xiàn)示例詳解

    這篇文章主要為大家介紹了kotlin android extensions 插件實現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-10-10
  • Android動態(tài)修改應用圖標與名稱的方法實例

    Android動態(tài)修改應用圖標與名稱的方法實例

    這篇文章主要給大家介紹了關于Android動態(tài)修改應用圖標與名稱的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-01-01
  • Android Studio修改Log信息顏色的實現(xiàn)

    Android Studio修改Log信息顏色的實現(xiàn)

    這篇文章主要介紹了Android Studio修改Log信息顏色的實現(xiàn),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-04-04
  • Android開源框架的SlidingFragment的使用示例

    Android開源框架的SlidingFragment的使用示例

    今天小編就為大家分享一篇關于Android開源框架的SlidingFragment的使用示例,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-03-03
  • android 定位的4種方式介紹

    android 定位的4種方式介紹

    開發(fā)中對于地圖及地理位置的定位是我們經(jīng)常要用地,地圖功能的使用使得我們應用功能更加完善,下面總結了一下網(wǎng)絡中現(xiàn)有對于介紹android定位的4種方式,希望對大家有幫助:
    2014-07-07
  • Flexbox+ReclyclerView實現(xiàn)流式布局

    Flexbox+ReclyclerView實現(xiàn)流式布局

    這篇文章主要為大家詳細介紹了Flexbox+ReclyclerView實現(xiàn)流式布局,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • Android編程之SMS讀取短信并保存到SQLite的方法

    Android編程之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)化

    這篇文章主要介紹了Android app開發(fā)中ListView的基本使用及優(yōu)化,ListView視圖組件是Android中最常用的組件之一需要的朋友可以參考下
    2016-02-02

最新評論