Here is the Android code for converting a View object to Bitmap without displaying it. This can be useful for displaying complex views in a Gallery widget.
Bitmap bmp = Bitmap.createBitmap(Utils.getPixelForDp(width, this), Utils.getPixelForDp(height, this), Bitmap.Config.ARGB_8888); View v = getLayoutInflater().inflate(layoutid, null); v.measure(MeasureSpec.makeMeasureSpec(bmp.getWidth(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(bmp.getHeight(), MeasureSpec.EXACTLY)); v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); v.draw(new Canvas(bmp));
Best source: Stackoverflow.com
Thank you so much for this. Other examples left off the “View.measure()” method which resulted in a blank screen. Yours works like a charm!
Cool webpage, can anybody recommend a better IDE then Eclipse for developing against Android? An environment like Visual Studio 2010 would be awesome 🙂
Sorry, but thanks to the plugins provided by Google, Eclipse is the easiest way to develop for Android. It’s not like VS, but can be customized. 🙂
Just cause it’s simple doesn’t mean it’s not super helfpul.