首页 > 其他 > 详细

Paint、Canvas.1

时间:2017-09-08 13:00:28      阅读:202      评论:0      收藏:0      [点我收藏+]

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);//坐标指的是左上角的位置

 

Paint、Canvas.1

原文:http://www.cnblogs.com/galibujianbusana/p/7493774.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!