drawpaint的类方法


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):"+(4*r)+"(4*g):"+(4*g)+"(4*b):"+(4*b));
}

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;
}


}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值