截图功能
/** * 对View进行量测,布局后截图 * @param view * @return */ public static Bitmap convertViewToBitmap(View view) { view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); view.setDrawingCacheEnabled(true); view.buildDrawingCache(); Bitmap bitmap = view.getDrawingCache(); return bitmap; }
设置缩略图:(比如用于微信分享)
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, 50, 100, true);