Android中的绘图

来源:互联网 发布:js indexof 多个 编辑:程序博客网 时间:2024/06/06 01:49

android中那些个优美的图形都是从最基础的东西话出来的,那今天我把自己所了解的画图做一个总结以后查询的时候会比较方便一些


首先明白的几个关键点是


1.Android是通过graphics类来显示图形的


1.1其中又包括了Canvas、Paint、Color、Bitmap等类


2.graphics类具备绘制  点 线   各种几何图形的能力


3. Paint类 
  和日常绘图一样,要绘制图形,首先得选择合适的画笔。那么同理android中绘图首先得调整画笔,按照自己的需要设置画笔的相关属性,系统给我提供的常用API如下: 
  setColor(); //设置画笔的颜色 
  setAntiAlias(); //设置画笔的锯齿效果 
  setARGB(); //设置画笔的A、R、G、B值 
  setAlpha(); //设置画笔的Alpha值 
  setTextSize(); //设置字体的尺寸 
  setStyle(); //设置画笔的风格(空心或实心) 
  setStrokeWidth(); //设置空心边框的宽度 
  getColor(); //获取画笔的颜色


Canvas 
  Canvas即画布,

       我们需要做的就是使用之前设置好的Paint来绘制图形。那么我们先看看系统给我们提供的方法: 
  canvas.drawLine(float startX, float startY, float stopX, float stopY, Paint paint);//绘制直线 
  canvas.drawRect(float left, float top, float right, float bottom, Paint paint);//绘制矩形 
  canvas.drawCircle(float cx, float cy, float radius, Paint paint);//绘制圆 
  canvas.drawArc(float cx, float cy, float radius, Paint paint);//绘制弧形、和扇形 
    canvas.drawText(String text, float x, float y, Paint paint);// 绘制字符 
  canvas.drawBitmap(Bitmap bitmap, float left, float top, Paint paint);//绘制Bitmap








0 0
原创粉丝点击