如何以编程方式创建带有文本的简单图像? [英] How to programmatically create simple image with text inside?
本文介绍了如何以编程方式创建带有文本的简单图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要以编程方式在应用程序中创建简单的图像.简单图像将具有黑色背景,并在其中以编程方式创建文本.有可能吗?
I need to create simple image in my application programmatically. Simple image will have black background with text inside which is created programmatically. Is it possible?
推荐答案
int width = 200;
int height = 100;
Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setStyle(Paint.Style.FILL);
canvas.drawPaint(paint);
paint.setColor(Color.WHITE);
paint.setAntiAlias(true);
paint.setTextSize(14.f);
paint.setTextAlign(Paint.Align.CENTER);
canvas.drawText("Hello Android!", (width / 2.f) , (height / 2.f), paint);
然后执行您想对位图进行的所有操作.例如:
And then do whatever you wanted to do with the Bitmap. For example:
ImageView image = new ImageView();
image.setImageBitmap(bitmap);
这篇关于如何以编程方式创建带有文本的简单图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文