views:

214

answers:

2

Hi I am creating an edittext in android and i am able to select particular text in it, I want to convert the selected text into a bitmap or png image.. Is it possible

A: 

tell us more about it,what do you mean by text to bitmap?

Biber
This area is for answers only... if you want to comment, use the comments section.
Cristian
I have a EditText. I am able to select some text from the edit text, now I want to convert that selected text into a image(png or bitmap).
Shashi
A: 

You could create a custom class that extends ImageView... then, you override the onDraw method and use the canvas object to draw the text... something like this:

public void onDraw(Canvas canvas) {
    canvas.drawText(text, x, y, null);
}

You can also use a Paint object in order to format and change the text color. Here you have an example:

TextPaint textPaint = new TextPaint();
textPaint.setColor(Color.RED);
textPaint.setTextSize(32);
StaticLayout layoutText = new StaticLayout(textToDraw, textPaint,
    coordX, Layout.Alignment.ALIGN_NORMAL, 1, 1, true);

Once you have create the ImageView you could use the getDrawingCache method (http://is.gd/cFZUx) in order to get a Bitmap.

The advantage of using a ImageView subclass is that you could easly show the image into your application before you do whatever you want to do with the Bitmap.

Cristian