4

I created a layout xml file that contains an extended textview. What I want is to draw the textview in a bitmap. What do I have to do after inflating the view so that I can use the draw method on the my canvas?

Thanks

Tughi
  • 1,093
  • 1
  • 11
  • 20

1 Answers1

4

Below are the steps to perform what you want:

  1. You have to create a mutable Bitmap (with the size of the screen).
  2. Create a Canvas from that Bitmap.
  3. inflate your view, get a reference to it.
  4. Call your_view.draw(your_canvas).

That's all, in your Bitmap you will have your view and all of it children drawn.

Lucas S.
  • 13,391
  • 8
  • 46
  • 46
  • Thanks, I was doing the same think, but the drawing failed because my extended textview was doing something wrong. – Tughi Aug 07 '09 at 07:24
  • 2
    You also need to call layout.measure() and layout.layout() before rendering to a bitmap. – user1139880 Feb 26 '12 at 19:08