Android 手机应用的开发经验—QR生成器
2010-08-21 03:25:00 来源:WEB开发网{
super.onOptionsItemSelected(item);
switch(item.getItemId())
{
case 0:
openOptionsDialog();
break;
case 1:
finish();
break;
}
return true;
}
private void openOptionsDialog()
{
new AlertDialog.Builder(this)
.setTitle(R.string.app_about)
.setMessage(R.string.app_about_msg)
.setPositiveButton(R.string.str_ok,
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialoginterface, int i)
{
}
}
)
.show();
}
3.4:自定义产生QRCode的函数
难者不会,会者不难。这句话说的真好,你不要看下面的代码就寥寥几行,在这几行代码的背后,我可是费了很大功夫的。代码如下:
Java代码
public Bitmap AndroidQREncode(String strEncoding, int qrcodeVersion) {
Log.i("wwj", "QREncode");
Bitmap canvasBmp = null;
try {
// 构建QRCode编码对象
com.swetake.util.Qrcode testQrcode = new com.swetake.util.Qrcode();
/* L','M','Q','H' */
testQrcode.setQrcodeErrorCorrect('M');//错误修正率
/* "N","A" or other */
testQrcode.setQrcodeEncodeMode('B');
/* 0-20 */
testQrcode.setQrcodeVersion(qrcodeVersion);
// getBytes
byte[] bytesEncoding = strEncoding.getBytes("utf-8");
if (bytesEncoding.length > 0) {
// 转化成boolean数组
bEncoding = testQrcode.calQrcode(bytesEncoding);
int w = 320;
int h = 240;
canvasBmp = Bitmap.createBitmap(w, h, Config.ARGB_8888);//创建一个可改变的Bitmat对象
Canvas cn = new Canvas(canvasBmp);//创建Canvas对象
onDraw(cn);//调用画图函数
cn.save(Canvas.ALL_SAVE_FLAG);
更多精彩
赞助商链接