最后一个参数,有的是null,有的是new Paint出来的。这是为何?
paint = new Paint();//初始化画笔
public void onDraw(Canvas canvas){//自己写的绘制方法
canvas.drawColor(Color.WHITE);
canvas.drawBitmap(background, 0,0, null);//清背景
canvas.drawBitmap(qiPan, 10, 10, null);//绘制棋盘
for(int i=0; i<qizi.length; i++){
for(int j=0; j<qizi[i].length; j++){//绘制棋子
if(qizi[i][j] != 0){
canvas.drawBitmap(qizibackground, 9+j*34, 10+i*35, null);//绘制棋子的背景
if(qizi[i][j] == 1){//为黑帅时
canvas.drawBitmap(heiZi[0], 12+j*34, 13+i*35, paint);
}
else if(qizi[i][j] == 2){//为黑车时
canvas.drawBitmap(heiZi[1], 12+j*34, 13+i*35, paint);
}
else if(qizi[i][j] == 3){//为黑马时
canvas.drawBitmap(heiZi[2], 12+j*34, 13+i*35, paint);
}
else if(qizi[i][j] == 4){//为黑炮时
canvas.drawBitmap(heiZi[3], 12+j*34, 13+i*35, paint);
}
else if(qizi[i][j] == 5){//为黑士时
canvas.drawBitmap(heiZi[4], 12+j*34, 13+i*35, paint);
}
else if(qizi[i][j] == 6){//为黑象时
canvas.drawBitmap(heiZi[5], 12+j*34, 13+i*35, paint);
}
else if(qizi[i][j] == 7){//为黑兵时
canvas.drawBitmap(heiZi[6], 12+j*34, 13+i*35, paint);
}
else if(qizi[i][j] == 8){//为红将时
canvas.drawBitmap(hongZi[0], 12+j*34, 13+i*35, paint);
}
else if(qizi[i][j] == 9){//为红车时
canvas.drawBitmap(hongZi[1], 12+j*34, 13+i*35, paint);
}
else if(qizi[i][j] == 10){//为红马时
canvas.drawBitmap(hongZi[2], 12+j*34, 13+i*35, paint);
}
else if(qizi[i][j] == 11){//为红砲时
canvas.drawBitmap(hongZi[3], 12+j*34, 13+i*35, paint);
}
else if(qizi[i][j] == 12){//为红仕时
canvas.drawBitmap(hongZi[4], 12+j*34, 13+i*35, paint);
}
else if(qizi[i][j] == 13){//为红相时
canvas.drawBitmap(hongZi[5], 12+j*34, 13+i*35, paint);
}
else if(qizi[i][j] == 14){//为红卒时
canvas.drawBitmap(hongZi[6], 12+j*34, 13+i*35, paint);
}
}
}
}
canvas.drawBitmap(vs, 10, 360, paint);//绘制VS背景图
//绘制黑方的时间
canvas.drawBitmap(time, 81, 411, paint);//绘制冒号
int temp = this.heiTime/60;//换算时间
String timeStr = temp+"";//转换成字符串
if(timeStr.length()<2){//当不足两位时前面填0
timeStr = "0" + timeStr;
}
for(int i=0;i<2;i++){//循环绘制时间
int tempScore=timeStr.charAt(i)-'0';
canvas.drawBitmap(number[tempScore], 65+i*7, 412, paint);
}
//画分钟
temp = this.heiTime%60;
timeStr = temp+"";//转换成字符串
if(timeStr.length()<2){
timeStr = "0" + timeStr;//当长度小于2时在前面添加一个0
}
for(int i=0;i<2;i++){//循环
int tempScore=timeStr.charAt(i)-'0';
canvas.drawBitmap(number[tempScore], 85+i*7, 412, paint);//绘制
}
//开始绘制红方时间
canvas.drawBitmap(this.redtime, 262, 410, paint);//红方的冒号
int temp2 = this.hongTime/60;//换算时间
String timeStr2 = temp2+"";//转换成字符串
if(timeStr2.length()<2){//当不足两位时前面填0
timeStr2 = "0" + timeStr2;
}
for(int i=0;i<2;i++){//循环绘制时间
int tempScore=timeStr2.charAt(i)-'0';
canvas.drawBitmap(redNumber[tempScore], 247+i*7, 411, paint);//绘制
}
//画分钟
temp2 = this.hongTime%60;//求出当前的秒数
timeStr2 = temp2+"";//转换成字符串
if(timeStr2.length()<2){//不足两位时前面用0补
timeStr2 = "0" + timeStr2;
}
for(int i=0;i<2;i++){//循环绘制
int tempScore=timeStr2.charAt(i)-'0';
canvas.drawBitmap(redNumber[tempScore], 267+i*7, 411, paint);//绘制时间数字
}
if(caiPan == true){//当该玩家走棋时,即红方走棋
canvas.drawBitmap(right, 155, 420, paint);//绘制向右的指针
}
else{//黑方走棋,即电脑走棋时
canvas.drawBitmap(left, 120, 420, paint);//绘制向左的指针
}
canvas.drawBitmap(current, 138, 445, paint);//绘制当前文字
canvas.drawBitmap(sound2, 10, 440, paint);//绘制声音
if(activity.isSound){//如果正在播放声音
canvas.drawBitmap(sound3, 80, 452, paint);//绘制
}
canvas.drawBitmap(exit2, 250, 440, paint);//绘制退出按钮
if(status == 1){//当胜利时
canvas.drawBitmap(win, 85, 150, paint);//绘制胜利图片
canvas.drawBitmap(ok, 113, 240, paint);
}
if(status == 2){//失败后
canvas.drawBitmap(lost, 85, 150, paint);//绘制失败界面
canvas.drawBitmap(ok, 113, 236, paint);
}
}
------解决思路----------------------
弄错了,直接无视上面的。
paint的效果对于画bitmap来说主要是一些特殊效果,比如说透明度啊,如果不需要什么特殊处理的画也可以为null的