Esempio n. 1
0
  /** 构造函数,主要对一些对象初始化 */
  public MySurfaceView(Context context) {
    super(context);

    mHolder = this.getHolder(); // 获得SurfaceHolder对象
    mHolder.addCallback(this); // 添加状态监听

    mPaint = new Paint(); // 创建一个画笔对象
    mPaint.setColor(Color.WHITE); // 设置画笔的颜色为白色

    qPaint = new Paint(); // 创建一个画笔对象
    qPaint.setAntiAlias(true); // 消除锯齿
    qPaint.setStyle(Paint.Style.STROKE); // 设置画笔风格为描边
    qPaint.setStrokeWidth(3); // 设置描边的宽度为3
    qPaint.setColor(Color.GREEN); // 设置画笔的颜色为绿色

    // 创建路径对象
    mPath = new Path();
    qPath = new Path();
    tPath = new Path();

    // 设置坐标为50,100
    mX = 50;
    mY = 100;

    // 设置贝塞尔曲线的开始坐标为(10,200)
    qStartX = 10;
    qStartY = 200;

    setFocusable(true); // 设置焦点
  }
Esempio n. 2
0
    public void onDraw(Canvas canvas) {
      // 검정색 배경으로 지운다. 빈 화면이면 지우기만 하고 리턴
      canvas.drawColor(Color.BLACK);
      if (status == BLANK) {
        return;
      }

      // 도형 목록을 순회하면서 도형 정보대로 출력한다.
      int idx;
      for (idx = 0; idx < arShape.size(); idx++) {
        Paint Pnt = new Paint();
        Pnt.setAntiAlias(true);
        Pnt.setColor(arShape.get(idx).color);

        Rect rt = arShape.get(idx).rt;
        switch (arShape.get(idx).what) {
          case Shape.RECT:
            canvas.drawRect(rt, Pnt);
            break;
          case Shape.CIRCLE:
            canvas.drawCircle(
                rt.left + rt.width() / 2, rt.top + rt.height() / 2, rt.width() / 2, Pnt);
            break;
          case Shape.TRIANGLE:
            Path path = new Path();
            path.moveTo(rt.left + rt.width() / 2, rt.top);
            path.lineTo(rt.left, rt.bottom);
            path.lineTo(rt.right, rt.bottom);
            canvas.drawPath(path, Pnt);
            break;
        }
      }
    }
Esempio n. 3
0
    public void onDraw(Canvas canvas) {
      canvas.drawColor(Color.LTGRAY);
      Paint Pnt = new Paint();
      String str = "Custom Font Test";

      Pnt.setAntiAlias(true);
      Pnt.setTypeface(mFont);
      Pnt.setTextSize(30);
      canvas.drawText(str, 10, 40, Pnt);
    }
Esempio n. 4
0
  // 그리기
  void Draw(Canvas canvas) {
    Paint pnt = new Paint();
    pnt.setAntiAlias(true);

    int r;
    int alpha;

    for (r = rad, alpha = 1; r > 4; r--, alpha += 5) {
      pnt.setColor(Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color)));
      canvas.drawCircle(x, y, r, pnt);
    }
  }
Esempio n. 5
0
 public MyView(Context context) {
   super(context);
   paint = new Paint();
   paint.setColor(Color.BLUE);
   paint.setStyle(Paint.Style.STROKE); // 设置画笔风格为描边
   paint.setStrokeWidth(10);
   random = new Random();
   setFocusable(true);
   holder = getHolder();
   holder.addCallback(this);
   path = new Path();
 }
Esempio n. 6
0
  protected void onDraw(Canvas cs) {
    super.onDraw(cs);

    // 描画方法の設定
    Paint p = new Paint();
    p.setColor(Color.BLACK);
    p.setStyle(Paint.Style.FILL);
    p.setStrokeWidth(8);

    // 円の描画
    cs.drawCircle(x, y, 50, p);
  }
Esempio n. 7
0
 public void onDraw(Canvas canvas) {
   canvas.drawColor(Color.LTGRAY);
   Paint Pnt = new Paint();
   int y = 1;
   Pnt.setAntiAlias(true);
   Pnt.setTextSize(30);
   Pnt.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
   canvas.drawText("Font:Default", 10, y++ * 40, Pnt);
   Pnt.setTypeface(Typeface.create(Typeface.DEFAULT_BOLD, Typeface.NORMAL));
   canvas.drawText("Font:Default Bold", 10, y++ * 40, Pnt);
   Pnt.setTypeface(Typeface.create(Typeface.MONOSPACE, Typeface.NORMAL));
   canvas.drawText("Font:Monospace", 10, y++ * 40, Pnt);
   Pnt.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL));
   canvas.drawText("Font:Sans Serif", 10, y++ * 40, Pnt);
   Pnt.setTypeface(Typeface.create(Typeface.SERIF, Typeface.NORMAL));
   canvas.drawText("Font:Serif", 10, y++ * 40, Pnt);
 }
 @Override
 protected void onDraw(Canvas canvas) {
   super.onDraw(canvas);
   if (paint == null) {
     paint = new Paint();
     luar =
         new LinearGradient(
             0.f, 0.f, 0.f, this.getMeasuredHeight(), 0xffffffff, 0xff000000, TileMode.CLAMP);
   }
   int rgb = Color.HSVToColor(color);
   Shader dalam =
       new LinearGradient(0.f, 0.f, this.getMeasuredWidth(), 0.f, 0xffffffff, rgb, TileMode.CLAMP);
   ComposeShader shader = new ComposeShader(luar, dalam, PorterDuff.Mode.MULTIPLY);
   paint.setShader(shader);
   canvas.drawRect(0.f, 0.f, this.getMeasuredWidth(), this.getMeasuredHeight(), paint);
 }
Esempio n. 9
0
  public void draw() {
    Bitmap bitmap = Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    RectF rect = new RectF(8, 8, 192, 192);

    Paint p = new Paint();
    p.setAntiAlias(true);
    p.setStyle(Paint.Style.STROKE);
    p.setColor(ColS);
    p.setStrokeWidth(16);

    int S = 162;
    int H = 300;

    // S
    canvas.drawArc(rect, -90, S, false, p);

    p.setStyle(Paint.Style.FILL);
    p.setColor(ColM);

    H -= 90;
    canvas.drawCircle(100, 100, 72, p);

    p.setColor(ColH);
    p.setStrokeWidth(2);

    float sx, sy;
    sx = (float) (72 * Math.cos(Math.PI * H / 180));
    sy = (float) (72 * Math.sin(Math.PI * H / 180));

    canvas.drawLine(100, 100, sx + 100, sy + 100, p);

    ImageView clokImg;

    clokImg = (ImageView) findViewById(R.id.clokImage);
    clokImg.setImageBitmap(bitmap);

    // Hour picker
    Bitmap ColPickBmp = Bitmap.createBitmap(80, 50, Bitmap.Config.ARGB_8888);
    Canvas ColPickCanvas = new Canvas(ColPickBmp);
    ImageView colPickImg = (ImageView) findViewById(R.id.colorHou);

    rect = new RectF(0, 0, 80, 50);

    p = new Paint();
    p.setAntiAlias(true);
    p.setStyle(Paint.Style.FILL);
    p.setColor(ColH);
    ColPickCanvas.drawRect(rect, p);

    colPickImg.setImageBitmap(ColPickBmp);

    // Minute picker
    ColPickBmp = Bitmap.createBitmap(80, 50, Bitmap.Config.ARGB_8888);
    ColPickCanvas = new Canvas(ColPickBmp);
    colPickImg = (ImageView) findViewById(R.id.colorMin);

    rect = new RectF(0, 0, 80, 50);

    p = new Paint();
    p.setAntiAlias(true);
    p.setStyle(Paint.Style.FILL);
    p.setColor(ColM);
    ColPickCanvas.drawRect(rect, p);

    colPickImg.setImageBitmap(ColPickBmp);

    // Second picker
    ColPickBmp = Bitmap.createBitmap(80, 50, Bitmap.Config.ARGB_8888);
    ColPickCanvas = new Canvas(ColPickBmp);
    colPickImg = (ImageView) findViewById(R.id.colorSec);

    rect = new RectF(0, 0, 80, 50);

    p = new Paint();
    p.setAntiAlias(true);
    p.setStyle(Paint.Style.FILL);
    p.setColor(ColS);
    ColPickCanvas.drawRect(rect, p);

    colPickImg.setImageBitmap(ColPickBmp);
  }
Esempio n. 10
0
 public void onDraw(Canvas canvas) {
   Paint p = new Paint();
   p.setColor(Color.GREEN);
   canvas.drawCircle(x, y, 16, p);
 }