Last active
January 10, 2023 09:48
-
-
Save Rock610/8d64eb2f572558455aef00e2cadd8aba to your computer and use it in GitHub Desktop.
Converting a view to Bitmap without displaying it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Bitmap loadBitmapFromView(View v) { | |
int specWidth = View.MeasureSpec.makeMeasureSpec(900 /* any */, View.MeasureSpec.EXACTLY); | |
v.measure(specWidth, specWidth); | |
int questionWidth = v.getMeasuredWidth(); | |
Bitmap b = Bitmap.createBitmap( questionWidth, questionWidth, Bitmap.Config.ARGB_8888); | |
Canvas c = new Canvas(b); | |
c.drawColor(Color.WHITE); | |
v.layout(v.getLeft(), v.getTop(), v.getRight(), v.getBottom()); | |
v.draw(c); | |
return b; | |
} | |
http://stackoverflow.com/questions/2801116/converting-a-view-to-bitmap-without-displaying-it-in-android |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment