Android绘图具体应用方式总结

移动开发 Android
Android绘图方法很多种,用户可以在不同的需求情况下来选择一种合适自己的进行操作。那么在这里就总结了一些供大家参考学习。

Android操作系统中,有很多功能技巧可以帮助我们轻松的实现一些需求。比如对图像图像的处理等等。我们在这里就会为大家带来一些有关Android绘图的方法,希望能是朋友们充分掌握这方面的应用。#t#

绘制各种图形、文字使用Canvas类中drawRect、drawText等方法,详细函数列表以及参数说明可以查看sdk

图形的样式由paint参数控制

Paint类也有很多参数设置方法

坐标由Rect和RectF类管理

通过Canvas、Paint和Rect 就可以绘制游戏中需要的大多数基本图形了

Android绘图中需要注意的一些细节

绘制实心矩形,需要设置paint属性:paint.setStyle(Style.FILL); 通过Style的几个枚举值改变绘制样式

以下写的有点乱,随时添加一些记录点, 以后再整理啦~~~~~

1. Rect对象

一个区域对象Rect(left, top, right, bottom) , 是一个左闭右开的区域,即是说使用 Rect.contains(left, top)为true, Rect.contains(right, bottom)为false

2.drawLine方法

drawLine(float startX, float startY, float stopX, float stopY, Paint paint) 也是一个左闭右开的区间,只会绘制到stopX-1,stopY-1

验证方法:

 

  1. Canvas c = canvas;  
  2. paint.setColor(Color.RED);  
  3. c.drawLine(x, y, x+c.getWidth()-1, y, paint);  
  4. c.drawLine(x, y+height-1, x+c.getWidth(), y+height-1, paint);  
  5. paint.setColor(Color.BLUE);  
  6. c.drawPoint(x+c.getWidth()-1, y, paint); 

 

说明drawLine是没有绘制到右边最后一个点的

3.drawRect(Rect r, Paint paint)

当绘制空心矩形时,绘制的是一个左闭右闭的区域

验证方法:

 

  1. rect.set(x, y, x+width, y+height);  
  2. paint.setStyle(Style.STROKE);  
  3. paint.setColor(Color.BLUE);  
  4. c.drawRect(rect, paint);  
  5. paint.setColor(Color.RED);  
  6. c.drawLine(x, y, x+width, y, paint);  
  7. c.drawLine(x, y+height, x+width, y+height, paint);  
  8. c.drawLine(x, y, x, y+height, paint);  
  9. c.drawLine(x+width, y, x+width, y+height, paint); 

 

当绘制实心矩形时,绘制的是一个左闭右开的区域

验证方法:

 

  1. rect.set(x, y, x+width, y+height);  
  2. paint.setColor(Color.RED);  
  3. c.drawLine(x, y, x+width, y, paint);  
  4. c.drawLine(x, y+height, x+width, y+height, paint);  
  5. c.drawLine(x, y, x, y+height, paint);  
  6. c.drawLine(x+width, y, x+width, y+height, paint);  
  7. paint.setStyle(Style.FILL);  
  8. paint.setColor(Color.BLUE);  
  9. c.drawRect(rect, paint); 

 

这个规则跟j2me也是一样的,在j2me里,drawRect长宽会多画出1px。SDK的说明是:

The resulting rectangle will cover an area (width + 1) pixels wide by (height + 1) pixels tall. If either width or height is less than zero, nothing is drawn.

例如drawRect(10,10,100,1)绘制,结果是一个2px高的矩形,用fillRect(10,10,100,1),结果是一个1px高的矩形

以上就是对Android绘图的具体介绍。

责任编辑:曹凯 来源: 博客园
相关推荐

2010-01-27 14:24:28

Android界面互调

2010-03-04 11:36:02

Python提交表单

2009-12-28 10:47:58

WPF绘图

2010-01-27 17:45:15

Android应用技巧

2010-01-27 16:35:54

Android常用技巧

2021-11-26 00:01:26

可视化AP I数据

2010-01-26 14:38:08

Android数字证书

2014-04-29 14:49:37

OpenGL ES 2Android应用投影

2010-01-25 13:29:53

Android本地应用

2010-01-25 16:52:22

Android Int

2010-01-27 18:12:14

Android dia

2010-01-27 18:19:13

Android画图

2009-11-26 14:23:10

PHP正则模式修正符

2010-02-02 17:47:59

C++操作剪贴板

2010-01-27 16:30:47

Android选项卡

2017-03-20 16:30:15

Android退出应用优雅方式

2010-02-25 14:26:48

WCF特点

2010-01-25 14:25:33

Android Int

2012-04-25 09:52:05

Expression

2012-08-23 09:56:40

AJAX
点赞
收藏

51CTO技术栈公众号