create Text Bitmap - Android Graphics

Android examples for Graphics:Bitmap Create

Description

create Text Bitmap

Demo Code


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

public class Main {
    public static Bitmap createTextBitmap(String strText) {
        Bitmap textBmp = Bitmap.createBitmap(256, 256,
                Bitmap.Config.ARGB_8888);
        Canvas canvasTemp = new Canvas(textBmp);
        canvasTemp.drawColor(Color.BLACK);
        Paint p = new Paint();
        String familyName = "this is a test";
        Typeface font = Typeface.create(familyName, Typeface.BOLD);
        p.setColor(Color.RED);//from   w  w w.j a  va2 s  .c o m
        p.setTypeface(font);
        p.setTextSize(27);
        canvasTemp.drawText(strText, 0, 100, p);
        return textBmp;
    }
}

Related Tutorials