Selecting text from Edit Text and converting selected text into an image
I am cr开发者_高级运维eating 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
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.
精彩评论