Shashi
Shashi

Reputation: 591

Selecting text from Edit Text and converting selected text into an image

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

Upvotes: 1

Views: 1099

Answers (1)

Cristian
Cristian

Reputation: 200160

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 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.

Upvotes: 1

Related Questions