I am using below function to get bitmap from Text. I am not able to position the text in center of the bitmap. A single rule for all below cases to be centered.
"I" "W" "WM" "IQ"
Bitmap DevImjBitmapFrmTxtFnc(String TxtSrgPsgVal)
{
int TxtSyzVal = 100;
Paint PenPytVaj = new Paint(ANTI_ALIAS_FLAG);
PenPytVaj.setTextSize(TxtSyzVal);
PenPytVaj.setColor(Color.BLUE);
PenPytVaj.setTextAlign(Paint.Align.CENTER);
float TxtTitYcoVal = -PenPytVaj.ascent(); // ascent() is negative
int ImjWytVal = (int) (PenPytVaj.measureText(TxtSrgPsgVal) + 0.0f); // round
int ImjHytVal = (int) (TxtTitYcoVal + PenPytVaj.descent() + 0.0f);
Bitmap ImjBitmapVaj = Bitmap.createBitmap(ImjWytVal + TxtSyzVal, ImjHytVal + TxtSyzVal, Bitmap.Config.ARGB_8888);
Canvas ImjCanvasVaj = new Canvas(ImjBitmapVaj);
ImjCanvasVaj.drawText(TxtSrgPsgVal, 0, TxtTitYcoVal, PenPytVaj);
return ImjBitmapVaj;
}
Kindly ignore the diff way of naming the functions and variables used.