List of usage examples for android.view View layout
@SuppressWarnings({ "unchecked" }) public void layout(int l, int t, int r, int b)
This is the second phase of the layout mechanism.
From source file:Main.java
public static Bitmap getViewBitmap(View v) { v.setDrawingCacheEnabled(true);/*from w w w . j a v a 2s .co m*/ // this is the important code :) // Without it the view will have a dimension of 0,0 and the bitmap will // be null v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); v.buildDrawingCache(true); Bitmap bmp = Bitmap.createBitmap(v.getDrawingCache()); v.setDrawingCacheEnabled(false); // clear drawing cache return bmp; }
From source file:com.ada.utils.Ui.java
public static Bitmap createBitmapFromView(View v) { Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); v.layout(v.getLeft(), v.getTop(), v.getRight(), v.getBottom()); v.draw(canvas);/*from w w w . j ava2 s. c om*/ return bitmap; }
From source file:Main.java
public static Bitmap view2Bitmap(View view) { Bitmap bitmap = null;/*from www .j av a 2s .c o m*/ try { if (view != null) { view.setDrawingCacheEnabled(true); view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); view.buildDrawingCache(); bitmap = view.getDrawingCache(); } } catch (Exception e) { e.printStackTrace(); } return bitmap; }
From source file:Main.java
private static Bitmap loadBitmapFromView(View view) { int specWidth = View.MeasureSpec.makeMeasureSpec(0 /* any */, View.MeasureSpec.UNSPECIFIED); view.measure(specWidth, specWidth);/*w w w. j av a2 s .c o m*/ int questionWidth = view.getMeasuredWidth(); int questionHeight = view.getMeasuredHeight(); Bitmap bitmap = Bitmap.createBitmap(questionWidth, questionHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); view.draw(canvas); return bitmap; }
From source file:com.bobomee.android.common.util.ScreenUtil.java
/** * http://stackoverflow.com/questions/9791714/take-a-screenshot-of-a-whole-view *//*from w w w .j a v a 2 s . c o m*/ public static Bitmap shotView(View v, int width, int height) { Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); v.layout(0, 0, v.getLayoutParams().width, v.getLayoutParams().height); v.draw(c); return b; }
From source file:Main.java
public static Bitmap loadBitmapFromView(View v, int width, int height) { v.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); v.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY)); v.layout(0, 0, width, height); v.draw(c);//www . j a v a2 s .c o m return b; }
From source file:Main.java
public static Bitmap createDrawableFromView(Context context, View view) { Bitmap bit = null;//w ww . j ava2 s. c o m try { DisplayMetrics displayMetrics = new DisplayMetrics(); ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); view.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT)); view.measure(displayMetrics.widthPixels, displayMetrics.heightPixels); view.layout(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels); view.buildDrawingCache(); bit = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(bit); view.draw(canvas); } catch (NullPointerException e) { Log.e("NullPointerException", e.toString()); e.printStackTrace(); } return bit; }
From source file:Main.java
public static Bitmap loadBitmapFromView(View v, int width, int height) { v.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); long time = System.currentTimeMillis(); Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); v.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY)); v.layout(0, 0, width, height); v.draw(c);//from ww w . j a v a 2 s.c om Log.d("artbook", "load bitmap time: " + (System.currentTimeMillis() - time)); return b; }
From source file:com.bobomee.android.common.util.ScreenUtil.java
/** * http://stackoverflow.com/questions/12742343/android-get-screenshot-of-all-listview-items *//* w ww. j av a2s. c o m*/ public static Bitmap shotListView(ListView listview) { ListAdapter adapter = listview.getAdapter(); int itemscount = adapter.getCount(); int allitemsheight = 0; List<Bitmap> bmps = new ArrayList<Bitmap>(); for (int i = 0; i < itemscount; i++) { View childView = adapter.getView(i, null, listview); childView.measure(View.MeasureSpec.makeMeasureSpec(listview.getWidth(), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); childView.layout(0, 0, childView.getMeasuredWidth(), childView.getMeasuredHeight()); childView.setDrawingCacheEnabled(true); childView.buildDrawingCache(); bmps.add(childView.getDrawingCache()); allitemsheight += childView.getMeasuredHeight(); } Bitmap bigbitmap = Bitmap.createBitmap(listview.getMeasuredWidth(), allitemsheight, Bitmap.Config.ARGB_8888); Canvas bigcanvas = new Canvas(bigbitmap); Paint paint = new Paint(); int iHeight = 0; for (int i = 0; i < bmps.size(); i++) { Bitmap bmp = bmps.get(i); bigcanvas.drawBitmap(bmp, 0, iHeight, paint); iHeight += bmp.getHeight(); bmp.recycle(); bmp = null; } return bigbitmap; }
From source file:com.dv.Utils.Tools.java
/** * view?bitmap//from w w w . j a va2 s. c o m * * @param view * @return */ public static Bitmap convertViewToBitmap(View view) { view.destroyDrawingCache(); 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); Bitmap bitmap = view.getDrawingCache(true); return bitmap; }