• Paint、Canvas.1


    Canvas 方法详解

    1:translate(float dx, float dy)

    /**** 移动canvas的原点到(dx,dy),默认为(0,0) */

    public void translate(float dx, float dy);

    canvas.drawRect(0,0,300,200,rectPaint);

    canvas.translate(300,200);

    canvas.drawRect(0,0,400,400,rectPaint1);

     图:

    2:clipRect方法 

       该方法 clipRect(float left, float top, float right, float bottom, Op op)不支持硬件加速,故application加入以下代码。

     

     

    <application android:hardwareAccelerated="false">

    public boolean clipRect(float left, float top, float right, float bottom, Op op) ;

    public boolean clipRect(float left, float top, float right, float bottom);

    先看Op的几个属性:

    Region.Op.REPLACE  //后者的范围将全部进行显示,并覆盖交集

    Op.DIFFERENCE; // 显示前者与后者差集

    Op.INTERSECT; // 显示交集部分

    Op.REVERSE_DIFFERENCE  // 显示后者与前者差集

    Op.UNION; // 并集都会显示

    Op.XOR  // 显示部分为全集减去交集部分

    canvas.clipRect(0,0,500,500);

    canvas.drawColor(Color.RED);

    canvas.clipRect(0, 0, 200, 200);

    canvas.clipRect(100, 100, 300, 300,

    Region.Op.REPLACE);

    canvas.clipRect(0,0,250,250);

    canvas.drawColor(Color.GRAY);

    replace:

    union:

    XOR  :

    3:drawBitmap方法

    Bitmap bitmap1= BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher_round);

    canvas.drawBitmap(bitmap1, 220, 60, rectPaint);//坐标指的是左上角的位置

     4:drawpoints方法

    public void drawPoint(float x, float y, Paint paint);

    public void drawPoints(float[] pts, int offset, int count, Paint paint) ;

    public void drawPoints(float[] pts, Paint paint) ;

      参数pts ,offset(开始点),count()数目

    float[] pts=new float[]{100,100,200,200,67f,56f,78f,78f,123f,145f,231f,342f};

    canvas.drawPoints(pts,0,4,rectPaint);

      绘制效果就是2个点:(100,100),(200,200)

    今天多一点积累,明天少一分烦恼
  • 相关阅读:
    Java I/O的典型使用方式
    搜索--hiho 骑士问题
    编程之美--水王(找出出现超过1/2的数)
    深入理解java虚拟机之类文件结构以及加载
    【转载】Java JVM 运行机制及基本原理
    整数的划分总结(转)
    java静态方法和非静态方法
    mongodb 运行错误总结
    MongoDb windows环境安装,附百度云链接
    JAVA解析Json数据
  • 原文地址:https://www.cnblogs.com/galibujianbusana/p/7493774.html
Copyright © 2020-2023  润新知