代码~
private void drawQRCode(boolean[][] brect, int colorFill) {
int intPadding = 20;
Bitmap bmp = Bitmap.createBitmap(400, 800, Config.ARGB_8888);
Canvas ca = new Canvas(bmp);
// 先锁定surfaceHolder
ca = sfh.lockCanvas();
ca.drawColor(getResources().getColor(R.color.white)); Paint paint = new Paint();
// 设置画笔属性
paint.setStyle(Paint.Style.FILL);
paint.setColor(colorFill);
paint.setStrokeWidth(1.0F);
// 绘制二维码
for (int i = 0; i < brect.length; i++) {
for (int j = 0; j < brect.length; j++) {
if (brect[j][i]) {
ca.drawRect(new Rect(intPadding + j * 3 + 2, intPadding + i
* 3 + 2, intPadding + j * 3 + 2 + 3, intPadding + i
* 3 + 2 + 3), paint);
}
}
}
ca.save(Canvas.ALL_SAVE_FLAG);
ca.restore();
ca.drawBitmap(bmp, 10, 10, paint);
File f = new File("/mnt/sdcard/"+System.currentTimeMillis()+".png");
System.out.println(System.currentTimeMillis());
FileOutputStream fos = null;
try {
fos = new FileOutputStream(f);
bmp.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
Toast toast = Toast.makeText(MainActivity.this, "保存成功", Toast.LENGTH_SHORT);
toast.show();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast toast = Toast.makeText(MainActivity.this, "失败", Toast.LENGTH_SHORT);
toast.show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 解锁surfaceHolder,并绘图
sfh.unlockCanvasAndPost(ca);
}
看看问题在哪 好蛋疼。
private void drawQRCode(boolean[][] brect, int colorFill) {
int intPadding = 20;
Bitmap bmp = Bitmap.createBitmap(400, 800, Config.ARGB_8888);
Canvas ca = new Canvas(bmp);
// 先锁定surfaceHolder
ca = sfh.lockCanvas();
ca.drawColor(getResources().getColor(R.color.white)); Paint paint = new Paint();
// 设置画笔属性
paint.setStyle(Paint.Style.FILL);
paint.setColor(colorFill);
paint.setStrokeWidth(1.0F);
// 绘制二维码
for (int i = 0; i < brect.length; i++) {
for (int j = 0; j < brect.length; j++) {
if (brect[j][i]) {
ca.drawRect(new Rect(intPadding + j * 3 + 2, intPadding + i
* 3 + 2, intPadding + j * 3 + 2 + 3, intPadding + i
* 3 + 2 + 3), paint);
}
}
}
ca.save(Canvas.ALL_SAVE_FLAG);
ca.restore();
ca.drawBitmap(bmp, 10, 10, paint);
File f = new File("/mnt/sdcard/"+System.currentTimeMillis()+".png");
System.out.println(System.currentTimeMillis());
FileOutputStream fos = null;
try {
fos = new FileOutputStream(f);
bmp.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
Toast toast = Toast.makeText(MainActivity.this, "保存成功", Toast.LENGTH_SHORT);
toast.show();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast toast = Toast.makeText(MainActivity.this, "失败", Toast.LENGTH_SHORT);
toast.show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 解锁surfaceHolder,并绘图
sfh.unlockCanvasAndPost(ca);
}
看看问题在哪 好蛋疼。
for (int i = 0; i < brect.length; i++) {
for (int j = 0; j < brect.length; j++) {
if (brect[j][i]) {ca.drawRect(new Rect(intPadding + j * 3 + 2, intPadding + i
* 3 + 2, intPadding + j * 3 + 2 + 3, intPadding + i
* 3 + 2 + 3), paint);}
}
}ca.save(Canvas.ALL_SAVE_FLAG);
ca.restore();
把下面两句移到for循环里面试试