3

I have a TextView. I want to change/convert TextView into an image file and store it on external storage. Is this possible? How?

Arief Rivai
  • 228
  • 6
  • 19
  • When you say you want to change it into an image file, are you wanting to store an image of the TextView (a picture of the text in it)? – Blumer Oct 09 '12 at 20:54
  • Possible duplicate http://stackoverflow.com/questions/4167593/converting-a-textview-bitmap-imageview-and-nothings-showing-up – ChristopheCVB Oct 09 '12 at 20:57
  • @Blumer : Yeah, i mean it.. TextView -> picture of the text -> store it to to external storage (image file).. – Arief Rivai Oct 09 '12 at 21:03

1 Answers1

3

The general approach you will want to take is to ...

  • Create your TextView
  • Set its text, font, etc. as you like
  • Create a Bitmap object with the same dimensions as your TextView
  • Create a new Canvas from your Bitmap
  • Call the TextView.Draw(Canvas) function to render it onto to the canvas
  • Save the resulting Bitmap to a file

The Android documentation should be able to help you how to accomplish each of those sub-points.

Blumer
  • 5,005
  • 2
  • 33
  • 47
  • I was unable to get this to work. No errors, just the textview never was rendered. My textview is not shown anywhere on my UI and I was not able to force the layout to occur. So it was always width zero. I solved it by using canvas.drawText() and setting up my Paint to match my textView settings. – Brent K. Nov 03 '21 at 15:58