码迷,mamicode.com
首页 > 其他好文 > 详细

Paint、Canvas.1

时间:2017-09-08 13:31:04      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:详解   res   awr   union   ott   ted   resource   factor   round   

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

标签:详解   res   awr   union   ott   ted   resource   factor   round   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!