Draw text to create Bitmap Image - Android Graphics

Android examples for Graphics:Bitmap Create

Description

Draw text to create Bitmap Image

Demo Code


//package com.java2s;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Color;

import android.graphics.Paint;

public class Main {
    public static Bitmap createTxtImage(String txt, int txtSize) {
        Bitmap mbmpTest = Bitmap.createBitmap(txt.length() * txtSize + 4,
                txtSize + 4, Config.ARGB_8888);
        Canvas canvasTemp = new Canvas(mbmpTest);
        Paint p = new Paint();
        p.setAntiAlias(true);/*  w ww  .j  a  v a  2s  .c om*/
        p.setColor(Color.WHITE);
        p.setTextSize(txtSize);
        canvasTemp.drawText(txt, 2, txtSize - 2, p);
        return mbmpTest;
    }
}

Related Tutorials