Android 实现切圆图作为头像使用实例

Android 实现切圆图作为头像使用实例,第1张

概述Android切圆图效果图如下:MyView类publicclassMyViewextendsView{Bitmapbmp;Paintpaint=newPaint();

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.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 实现切圆图作为头像使用实例全部内容,希望文章能够帮你解决Android 实现切圆图作为头像使用实例所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1147371.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-31
下一篇2022-05-31

发表评论

登录后才能评论

评论列表(0条)

    保存