Android Snippet: Draw layout to a Bitmap

29 Dec
December 29, 2012

I needed this code for a project, where I needed to capture a certain list item I was rendering into a Bitmap and upload it usingĀ Facebook’s SDK.

This snippet basically “screen captures” and draws a certain view and saves it as a Bitmap and is the right way to do this.

Another solution to this is trying to draw everything on Canvas* “manually”, but taking the time to figure out all the bounds and text sizes, and getting the exact positions of things on a canvas sound like a real inconvenience. This makes it the wrong way to do this.

And you’re done!

Tags: , , , , ,
4 replies
  1. Patryk says:

    Cool thing, I made a small project from that some time ago
    https://github.com/p47/ScreenShoter

    Reply
  2. nadavfima says:

    Using the same technique, right?

    Reply
  3. Felipe Calderon barragan says:

    greetings.

    I love this library and I added one of my projects. the problem is that when viewing the interface under OS Ice Cream Sandwich looks like the picture shows. Can you tell me a way to correct it and make the correction. I am willing to work on it but can not find the way to make it compatible for minor API.

    http://imageshack.us/photo/my-images/820/cardsengingerbread.png/

    Reply
  4. expert zone says:

    I do not even understand how I stopped up right here, however I believed this post was once
    great. I dont know who you are but definitely you are going to a well-known blogger if you are not already
    Cheers!

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>