Last active
January 25, 2016 08:31
-
-
Save twiceyuan/38a54a5679b9a034d135 to your computer and use it in GitHub Desktop.
将 View 显示出来的图像转换为 Bitmap
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
/** | |
* 转换 View 为 Bitmap | |
*/ | |
public static Bitmap viewToBitmap(View v) { | |
if (v.getMeasuredHeight() <= 0) { | |
v.measure(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); | |
Bitmap b = Bitmap.createBitmap(v.getMeasuredWidth(), v.getMeasuredHeight(), Bitmap.Config.ARGB_8888); | |
Canvas c = new Canvas(b); | |
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); | |
v.draw(c); | |
return b; | |
} | |
Bitmap b = Bitmap.createBitmap(v.getMeasuredWidth(), v.getMeasuredHeight(), Bitmap.Config.ARGB_8888); | |
Canvas c = new Canvas(b); | |
v.layout(v.getLeft(), v.getTop(), v.getRight(), v.getBottom()); | |
v.draw(c); | |
return b; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment