Android 使用canvas.drawText方法画数字,怎么把字体弄大,而细
Canvas相当于画布,字体的大小格式在Paint上设置才正确, Paint 相当于画笔。代码如下,没有具体参数:希望能帮到你
Paint paint = new Paint();
paint.setTextSize(textSize);//设置字体大小
paint.setTypeface(typeface);//设置字体类型
canvas.drawText(text, x, y, paint);//使用画笔paint
android canvas的drawText方法 如何设置字体大小和格式。
Canvas相当于画布,字体的大小格式在Paint上设置才正确,
Paint
相当于画笔。代码如下,没有具体参数:希望能帮到你
Paint
paint
=
new
Paint();
paint.setTextSize(textSize);//设置字体大小
paint.setTypeface(typeface);//设置字体类型
canvas.drawText(text,
x,
y,
paint);//使用画笔paint
android 在canvas画了一张图片在代码中我怎么得到它
参见代码:
/////////////////////////////////////////////////////////////////////////;
// Save canvas to file.
// Get the width and height of screen.
DisplayMetrics display = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(display);
int width = display.widthPixels;
int height = display.heightPixels;
// Create bitmap.
Bitmap bt = Bitmap.createBitmap(width, height, Config.ARGB_8888);
// Create canvas.
Canvas canvas = new Canvas();
canvas.setBitmap(bt);
Paint paint = new Paint();
// Draw a oval.
int left = width>>2;
int right = left*3;
int top = height>>2;
int bottom = top*3;
paint.setStyle(Style.STROKE);
canvas.drawOval(new RectF(left,top,right,bottom), paint);
// Draw text.
paint.setTextAlign(Align.CENTER);
paint.setColor(Color.RED);
canvas.drawText("Hi,man!", width>>1, height>>1,paint);
// Save canvas.
canvas.save(Canvas.ALL_SAVE_FLAG);
canvas.restore();
//Save canvas to file.
File file = new File(getFilesDir(), "hiMan.png");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
bt.compress(Bitmap.CompressFormat.PNG, 50, fos);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}