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
views:
214answers:
2This area is for answers only... if you want to comment, use the comments section.
Cristian
2010-06-07 15:34:32
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
2010-06-08 04:50:31
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
2010-06-07 15:33:43