Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Generate bitmap of a view without drawing
    text
    copied!<p>We have a problem to generate a bitmap from a particular view. The restriction is that it can not be rendered view (drawing). Does anyone have any tips how to solve this?</p> <p>The documentation of the class view (<a href="http://developer.android.com/reference/android/view/View.html" rel="nofollow">http://developer.android.com/reference/android/view/View.html</a>) has some explanation of the steps used by Android to render a View. In the case, we would get in step "layout", but not in the "drawing". Anyone who has any idea, could show an example?</p> <p>My code is generating the exception: error -> width and height must be> 0</p> <pre><code>... public static Bitmap loadBitmapFromView(View v) { Bitmap b = null; try { b = Bitmap.createBitmap( v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); v.measure(v.getWidth(), v.getHeight()); v.layout(0, 0, v.getWidth(), v.getHeight()); v.draw(c); } catch (Exception e) { Log.e(MainActivity.TAG, "error -&gt; "+e.getMessage()); } return b; } public void snap(View v) { LayoutInflater inflate = (LayoutInflater) getBaseContext() .getSystemService(LAYOUT_INFLATER_SERVICE); View view = new View(getBaseContext()); view = inflate.inflate(R.layout.list_item, null); Log.d(MainActivity.TAG, "getWidth -&gt; "+view.getWidth()); Log.d(MainActivity.TAG, "getHeight -&gt; "+view.getHeight()); Bitmap b = loadBitmapFromView(view); if (b != null) { LinearLayout mainLayout = (LinearLayout) findViewById(R.id.LinearLayout1); ImageView image = new ImageView(this); image.setImageBitmap(b); mainLayout.addView(image); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload