Android 手机应用的开发经验—QR生成器
2010-08-21 03:25:00 来源:WEB开发网);
}
}
}
//解锁并绘图
mSurfaceHolder01.unlockCanvasAndPost(mCanvas01);
}
//在SurfaceView上绘制QRCode条形码
private void drawQRCode(boolean[][] bRect, int colorFill)
{
/* test Canvas*/
int intPadding = 20;
//绘图前先锁定Surfaceholder
Canvas mCanvas01 = mSurfaceHolder01.lockCanvas();
//设置画图绘图颜色
mCanvas01.drawColor(getResources().getColor(R.drawable.white));
//创建画笔
Paint mPaint01 = new Paint();
//设置画笔颜色和模式
mPaint01.setStyle(Paint.Style.FILL);
mPaint01.setColor(colorFill);
mPaint01.setStrokeWidth(1.0F);
//逐一加载boolean数组
for (int i=0;i
< p>
{
for (int j=0;j
< p>
{
if (bRect[j][i])
{
//绘出条形码方块
mCanvas01.drawRect
(
new Rect
(
intPadding+j*3+2,//左上边x
intPadding+i*3+2,//左上边y
intPadding+j*3+2+3,//右下边x
intPadding+i*3+2+3//右下边y
), mPaint01
);
}
}
}
//解锁并绘图
mSurfaceHolder01.unlockCanvasAndPost(mCanvas01);
}
代码片段中用到的boolean数组就是从AndroidQREncode()函数中得到的。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Canvas和Bitmap绘图
Canvas可以用来显示位图,可是Canvas画图本身位图没有关系,不过可以把Canvas和Bitmap联系起来,这样图像保存时候就大有用途了。你还记得这两行代码吗:
canvasBmp = Bitmap.createBitmap(w, h, Config.ARGB_8888);//创建可改变的Bitmat对象
Canvas cn = new Canvas(canvasBmp);//创建Canvas对象
更多精彩
赞助商链接