效果图如下:

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>

更多相关文章

  1. android OOM的那些事
  2. android上类似iphone上的开关按钮
  3. 【Android】开源项目汇总
  4. Android中FloatingActionButton的基本使用
  5. Android显示圆角图片,可指定图片某几个角为圆角
  6. Android(安卓)关于fragment切换
  7. Android入门之Activity的四种启动模式
  8. ExpandableListView(一)替换系统默认的箭头
  9. Android两种杀掉进程方式总结(System.exit()和Process.killProce

随机推荐

  1. 经典Android试题及答案
  2. TextView(标签控件)
  3. Android设备的唯一标识
  4. Android Studio下载及离线升级方法
  5. Android用户界面 UI组件--自动提示输入框
  6. Android xml中 @和?区别,style和attr小结
  7. Android中的5大布局和网格布局
  8. Android(安卓)Studio简单设置
  9. LoganSquare——快速解析和序列化JSON对
  10. Android Gesture Detector