本文介绍了如何编程创建简单的形象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要在我的应用程序编程方式创建简单的图像。简单的形象是黑色背景,这是编程创建的文本。可能吗?谢谢。
解决方案
INT宽度= 200;
INT高= 100;
点阵位图= Bitmap.createBitmap(宽度,高度,Config.ARGB_8888);
帆布油画=新的Canvas(位);
涂料粉刷=新的油漆();
paint.setColor(Color.BLACK);
paint.setStyle(Paint.Style.FILL);
canvas.drawPaint(油漆);
paint.setColor(Color.WHITE);
paint.setAntiAlias(真正的);
paint.setTextSize(14.f);
paint.setTextAlign(Paint.Align.CENTER);
canvas.drawText(你好Android的!(宽/ 2.F),(身高/ 2.F),油漆);
然后你想什么做的位图。例如:
ImageView的形象=新ImageView的();
image.setImageBitmap(位);
I need to create simple image in my application programatically. Simple image is black background with text which is created programatically. Is it possible? Thank you.
解决方案
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);
这篇关于如何编程创建简单的形象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!