«

drawpaint的类方法

时间:2024-3-2 20:00     作者:韩俊     分类: Android


import android.content.Context;

import android.graphics.Bitmap;

import android.graphics.Bitmap.Config;

import android.graphics.Canvas;

import android.graphics.Color;

import android.graphics.Paint;

import android.graphics.Paint.Style;

import android.util.Log;

import android.view.View;





class DrawCG extends View {





private static final String tag = "DrawCG";

private Paint paint;

private Canvas canv;

private Bitmap mBitmap;





// private EditText r1;

// private EditText g1;

// private EditText b1;





public DrawCG(Context context, int width, int height) {

super(context);

// 声明画笔

paint = new Paint();

// 设置颜色

paint.setColor(Color.RED);

// 设置抗锯齿

paint.setAntiAlias(true);

// 设置线宽

paint.setStrokeWidth(3);

// 设置非填充

paint.setStyle(Style.STROKE);

// 声明位图

mBitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);

// 声明画布

canv = new Canvas(mBitmap);

}





@Override

protected void onDraw(Canvas canvas) {

canvas.drawBitmap(mBitmap, 0, 0, null);

// super.onDraw(canvas);

}





/**

  • RED

  • @return

    */

    public Bitmap drawRed() {

    // canv.drawLine(200, 50, 600, 50, paint);

    // canv.drawARGB(64,3, 3, 3);

    canv.drawColor(Color.RED);





    return mBitmap;





    }





    /**
  • blue

  • @return

    */

    public Bitmap drawBlue() {

    canv.drawColor(Color.BLUE);

    return mBitmap;

    }





    /**
  • green

  • @return

    /

    public Bitmap drawGreen() {





    // canv.drawRect(new Rect(150, 150, 500, 500), paint);

    canv.drawColor(Color.GREEN);





    return mBitmap;

    }





    /

  • black

    /

    public Bitmap drawBlack() {





    // canv.drawRect(new Rect(150, 150, 500, 500), paint);

    canv.drawColor(Color.BLACK);





    return mBitmap;

    }





    /

  • white

    /

    public Bitmap drawWhite() {





    // canv.drawRect(new Rect(150, 150, 500, 500), paint);

    canv.drawColor(Color.WHITE);





    return mBitmap;

    }





    /*
  • 255灰阶

    /

    public Bitmap paintBitmap(int r, int g, int b) {

    Log.e(tag, "调用画图的方法,这里传入参数, r-->" + r + "| g--->" + g + "|b--->" + b);

    canv.drawRGB(r, g, b);

    return mBitmap;





    }





    /*
  • 64灰阶

    /

    public Bitmap Onehuijie(int r, int g, int b) {

    Log.e(tag, "64 4灰阶调用");

    // canv.drawARGB(32, 4
    r - 1, 4 g - 1, 4 b - 1);





    if ((r == 64) | (g == 64) |( b == 64)) {

    canv.drawRGB(255, 255, 255);

    Log.e(tag, "r ,g ,b 的值都是 255 , 255, 255");

    }else {

    canv.drawRGB(4 r , 4 g , 4 b);

    Log.e(tag, "64灰阶计算执行,(4
    r):"+(4r)+"(4g):"+(4g)+"(4b):"+(4b));

    }



    return mBitmap;

    }





    /

  • 外围白,中心黑

    /

    public Bitmap BB(float left, float top, float right, float bottom) {

    Log.e(tag, "外围白,中心黑class");

    canv.drawColor(Color.WHITE);

    Paint paint = new Paint();

    paint.setColor(Color.BLACK); // 设置画笔颜色

    paint.setStyle(Style.FILL);// 设置填充样式

    paint.setStrokeWidth(15);// 设置画笔宽度

    // canv.drawRect(135, 444, 1000, 1332, paint);

    // canv.drawRect(left / 8, top / 4, right 7 / 8, bottom 3 / 4,

    // paint);// 直接构造

    canv.drawRect(left / 4, top / 4, right 3 / 4, bottom 3 / 4, paint);// 直接构造

    return mBitmap;

    }





    public Bitmap Bh(float left, float top, float right, float bottom) {

    Log.e(tag, "外围白,中心huiclass");

    canv.drawColor(Color.WHITE);

    Paint paint = new Paint();

    paint.setColor(Color.rgb(128, 128, 128)); // 设置画笔颜色

    paint.setStyle(Style.FILL);// 设置填充样式

    paint.setStrokeWidth(15);// 设置画笔宽度





    canv.drawRect(left / 4, top / 4, right 3 / 4, bottom 3 / 4, paint);// 直接构造

    return mBitmap;

    }





    public Bitmap BJ(float left, float top, float right, float bottom) {

    Log.e(tag, "外围灰色,中心白class");

    canv.drawColor(Color.rgb(128, 128, 128));

    Paint paint = new Paint();

    paint.setColor(Color.WHITE); // 设置画笔颜色

    paint.setStyle(Style.FILL);// 设置填充样式

    paint.setStrokeWidth(15);// 设置画笔宽度





    canv.drawRect(left / 4, top / 4, right 3 / 4, bottom 3 / 4, paint);// 直接构造

    return mBitmap;

    }





    public Bitmap BK(float left, float top, float right, float bottom) {

    Log.e(tag, "外围灰色,中心blackclass");

    canv.drawColor(Color.rgb(128, 128, 128));

    Paint paint = new Paint();

    paint.setColor(Color.BLACK); // 设置画笔颜色

    paint.setStyle(Style.FILL);// 设置填充样式

    paint.setStrokeWidth(15);// 设置画笔宽度





    canv.drawRect(left / 4, top / 4, right 3 / 4, bottom 3 / 4, paint);// 直接构造

    return mBitmap;

    }





    }

        <p>版权声明:本文为博主原创文章,未经博主允许不得转载。</p>

标签: android

热门推荐