Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
251 views
Welcome To Ask or Share your Answers For Others

1 Answer

    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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...