Skip to content

Instantly share code, notes, and snippets.

@farooqkhan003
Created August 31, 2017 07:40
Show Gist options
  • Select an option

  • Save farooqkhan003/6017207a1e9ce2210a8a3b27f9e4b063 to your computer and use it in GitHub Desktop.

Select an option

Save farooqkhan003/6017207a1e9ce2210a8a3b27f9e4b063 to your computer and use it in GitHub Desktop.
public Bitmap createBitmapFromView(View v) {
v.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT));
v.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
Bitmap bitmap = Bitmap.createBitmap(v.getMeasuredWidth(),
v.getMeasuredHeight(),
Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bitmap);
v.layout(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
v.draw(c);
return bitmap;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment