Android--paint应用举例

android 用paint,canvas 绘图

(1)主要用了paint ,canvas 两个类中的方法

(2)主要用了画线和画圆的方法。

(3)drawline(起始点轴坐标,起始点y轴坐标,终点轴坐标,终点y轴坐标)

(4)drawcircle(圆心x轴坐标,圆心y轴坐标,半径,画布)

效果图:

直接上代码了:

package com.example.drawpicture;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
class Customview1 extends View{
Paint  paint;
  public Customview1(Context context) {
      super(context);
      paint = new Paint();
      paint.setColor(Color.BLACK);
      paint.setStrokeJoin(Paint.Join.ROUND);
      paint.setStrokeCap(Paint.Cap.ROUND);
      paint.setStrokeWidth(3);
      paint.setTextSize(40);//设置字体大小
          }
      protected void onDraw(Canvas canvas)        {
      //横线            //top
      canvas.drawLine(30, 30, 450,30, paint);
      canvas.drawLine( 30, 100, 450,100, paint);
      canvas.drawLine( 30, 170, 450,170, paint);
      canvas.drawLine( 30, 240, 450,240, paint);
      canvas.drawLine( 30, 310, 450,310, paint);
      // bottom
      canvas.drawText(" 楚   河 ", 65, 355, paint);//使用画笔paint
    canvas.drawText(" 汉  界  ", 320,355 , paint);//使用画笔paint
    canvas.drawLine(30, 380, 450,380, paint);
    canvas.drawLine( 30, 450, 450,450, paint);
    canvas.drawLine( 30, 520, 450,520, paint);
    canvas.drawLine( 30, 590, 450,590, paint);
    canvas.drawLine( 30, 660, 450,660, paint);
    //竖线
    //left
    canvas.drawLine(30, 30,30,660, paint);
    canvas.drawLine(83, 30, 83,310, paint);
    canvas.drawLine(136, 30, 136,310, paint);
    canvas.drawLine(189, 30, 189,310, paint);
    canvas.drawLine(242, 30, 242,310, paint);
    canvas.drawLine(294, 30, 294,310, paint);
    canvas.drawLine(347, 30, 347,310, paint);
    canvas.drawLine(398, 30, 398,310, paint);
    //right
    canvas.drawLine(83, 380, 83,660, paint);
    canvas.drawLine(136, 380, 136,660, paint);
    canvas.drawLine(189, 380, 189,660, paint);
    canvas.drawLine(242, 380, 242,660, paint);
    canvas.drawLine(294, 380, 294,660, paint);
    canvas.drawLine(347, 380, 347,660, paint);
    canvas.drawLine(398, 380, 398,660, paint);
    canvas.drawLine(450,30 ,450,660, paint);
     //大营
   canvas.drawLine(189, 30, 294,170, paint);
    canvas.drawLine(294, 30, 189,170, paint);
    canvas.drawLine(189,520, 294,660, paint);
    canvas.drawLine(294,520, 189,660, paint);
     //topcircle
     canvas.drawCircle(450, 240,20, paint);
     canvas.drawCircle(346, 240,20, paint);
     canvas.drawCircle(242, 240,20, paint);
     canvas.drawCircle(396, 170,20, paint);
     canvas.drawCircle(450, 30,20, paint);
     canvas.drawCircle(396, 30,20, paint);
     canvas.drawCircle(346, 30,20, paint);
     canvas.drawCircle(294, 30,20, paint);
     canvas.drawCircle(242, 30,20, paint);
     canvas.drawCircle(189, 30,20, paint);
     canvas.drawCircle(135, 30,20, paint);
     canvas.drawCircle(83, 30,20, paint);
     canvas.drawCircle(30, 30,20 , paint);
     canvas.drawCircle(83, 170,20, paint);
     canvas.drawCircle(135, 240,20, paint);
     canvas.drawCircle(30, 240,20, paint);
     //bottomcircle
     canvas.drawCircle(450, 450,20, paint);
     canvas.drawCircle(346, 450,20, paint);
     canvas.drawCircle(242, 450,20, paint);
     canvas.drawCircle(396, 520,20, paint);
     canvas.drawCircle(450, 660,20, paint);
     canvas.drawCircle(396, 660,20, paint);
     canvas.drawCircle(346, 660,20, paint);
     canvas.drawCircle(294, 660,20, paint);
     canvas.drawCircle(242, 660,20, paint);
     canvas.drawCircle(189, 660,20, paint);
     canvas.drawCircle(135, 660,20, paint);
     canvas.drawCircle(83, 660,20, paint);
     canvas.drawCircle(30, 660,20, paint);
     canvas.drawCircle(83, 520,20, paint);
     canvas.drawCircle(135, 450,20, paint);
     canvas.drawCircle(30, 450,20, paint);
     paint.setColor(Color.RED);
     paint.setTextSize(20);
     canvas.drawText("兵", 21,458, paint);
     canvas.drawText("兵", 127,458, paint);
     canvas.drawText("兵", 232,458 , paint);
     canvas.drawText("炮", 388,527, paint);
     canvas.drawText("车", 440,668 , paint);
     canvas.drawText("馬", 388,668 , paint);
     canvas.drawText("象", 335,668 , paint);
     canvas.drawText("仕", 285,668 , paint);
     canvas.drawText("帥", 232,668 , paint);
     canvas.drawText("仕", 180,668 , paint);
     canvas.drawText("象", 127,668 , paint);
     canvas.drawText("馬", 72,668 , paint);
     canvas.drawText("车", 21,668 , paint);
     canvas.drawText("炮", 72, 527, paint);
     canvas.drawText("兵", 335,458 , paint);
     canvas.drawText("兵", 440,458, paint);
     canvas.drawText("卒", 21,245, paint);
     canvas.drawText("卒", 127,245, paint);
     canvas.drawText("卒", 232,245 , paint);
     canvas.drawText("炮", 72, 177, paint);
     canvas.drawText("车", 21,35 , paint);
     canvas.drawText("馬", 72,35 , paint);
     canvas.drawText("象", 127,35 , paint);
     canvas.drawText("士", 180,35 , paint);
     canvas.drawText("将", 232,35 , paint);
     canvas.drawText("士", 285,35 , paint);
     canvas.drawText("象", 335,35 , paint);
     canvas.drawText("馬", 388,35 , paint);
     canvas.drawText("车", 440,35 , paint);
     canvas.drawText("炮", 388, 177, paint);
     canvas.drawText("卒", 335,247 , paint);
     canvas.drawText("卒", 440,247, paint);
     }
      }
时间: 2024-11-10 13:58:59

Android--paint应用举例的相关文章

Android Paint的使用以及方法介绍(附源码下载)

要绘图,首先得调整画笔,待画笔调整好之后,再将图像绘制到画布上,这样才可以显示在手机屏幕上.Android 中的画笔是 Paint类,Paint 中包含了很多方法对其属性进行设置,主要方法如下: setAntiAlias: 设置画笔的锯齿效果.    setColor: 设置画笔颜色    setARGB:  设置画笔的a,r,p,g值.    setAlpha:  设置Alpha值    setTextSize: 设置字体尺寸.    setStyle:  设置画笔风格,空心或者实心.    

7种形式的Android Dialog使用举例

7种形式的Android Dialog使用举例 在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,在我们使用Android的过程中,我归纳了一下,Android Dialog的类型无非也就7种,下面我分别向大家介绍这7种Android Dialog对话框的使用方法,希望对大家能有所帮助. 1.该效果是当按返回按钮时弹出一个提示,来确保无误操作,采用常见的对话框样式. 创建dialog对话框方

Android Paint之PathEffect详解

尊重原创,转载请标明出处    http://blog.csdn.net/abcdef314159 在之前讲Android Paint的使用详解的时候,其中有一个方法setPathEffect(PathEffect effect)没有详细介绍,这篇就结合代码来介绍一下,在之前说过PathEffect共有6个子类ComposePathEffect,CornerPathEffect,DashPathEffect,DiscretePathEffect,PathDashPathEffect,SumPat

Android ---paint类

引自:http://www.cnblogs.com/-OYK/archive/2011/10/25/2223624.html Android Paint和Color类 要绘图,首先得调整画笔,待画笔调整好之后,再将图像绘制到画布上,这样才可以显示在手机屏幕上.Android 中的画笔是 Paint类,Paint 中包含了很多方法对其属性进行设置,主要方法如下: setAntiAlias: 设置画笔的锯齿效果.    setColor: 设置画笔颜色    setARGB:  设置画笔的a,r,p

【转】Android Paint之 setXfermode PorterDuffXfermode 讲解

[置顶] Android Paint之 setXfermode PorterDuffXfermode 讲解 分类: android动效篇2015-04-07 17:23 978人阅读 评论(8) 收藏 举报 setXfermodePorterDuffXfermode图层混合模式android图像混合模式AvoidXfermode 尊重原创,欢迎转载,转载请注明: FROM  GA_studio   http://blog.csdn.net/tianjian4592 前面关于paint的方法讲解里

Android Paint之ColorFilter详解

尊重原创,转载请标明出处    http://blog.csdn.net/abcdef314159 在之前讲到Android Paint的使用详解的时候,其中setColorFilter(ColorFilter filter)方法没有讲,今天就来简单的分析一下,在Android中ColorFilter共有3个子类,ColorMatrixColorFilter,LightingColorFilter,PorterDuffColorFilter,今天先来看第一个ColorMatrixColorFil

Android Paint之 setXfermode PorterDuffXfermode 讲解

setXfermodePorterDuffXfermode图层混合模式android图像混合模式AvoidXfermode 尊重原创,欢迎转载,转载请注明: FROM  GA_studio   http://blog.csdn.net/tianjian4592 前面关于paint的方法讲解里,讲到 setXfermode 就截止了,原因有两个: 1. 那篇文章已经太长了,我自己都看不下去了: 2. setXfermode 在paint 里占有至关重要的地位: 基于以上两个原因,我们一起来看看这个

Android Paint Xfermode 学习小结

一.setXfermode(Xfermode xfermode) Xfermode国外有大神称之为过渡模式,这种翻译比较贴切但恐怕不易理解,大家也可以直接称之为图像混合模式,因为所谓的"过渡"其实就是图像混合的一种,这个方法跟我们上面讲到的setColorFilter蛮相似的.查看API文档发现其果然有三个子类:AvoidXfermode, PixelXorXfermode和PorterDuffXfermode,这三个子类实现的功能要比setColorFilter的三个子类复杂得多.

Android Paint和Color类

要绘图,首先得调整画笔,待画笔调整好之后,再将图像绘制到画布上,这样才可以显示在手机屏幕上.Android 中的画笔是 Paint类,Paint 中包含了很多方法对其属性进行设置,主要方法如下: setAntiAlias: 设置画笔的锯齿效果.    setColor: 设置画笔颜色    setARGB:  设置画笔的a,r,p,g值.    setAlpha:  设置Alpha值    setTextSize: 设置字体尺寸.    setStyle:  设置画笔风格,空心或者实心.   

Android Paint和Color类绘画实例

要绘图,首先得调整画笔,待画笔调整好之后,再将图像绘制到画布上,这样才可以显示在手机屏幕上.Android 中的画笔是 Paint类,Paint 中包含了很多方法对其属性进行设置,主要方法如下: setAntiAlias: 设置画笔的锯齿效果.    setColor: 设置画笔颜色    setARGB:  设置画笔的a,r,p,g值.    setAlpha:  设置Alpha值    setTextSize: 设置字体尺寸.    setStyle:  设置画笔风格,空心或者实心.