List of usage examples for android.view View draw
@CallSuper public void draw(Canvas canvas)
From source file:org.tomahawk.tomahawk_android.fragments.ContextMenuFragment.java
private void setupBlurredBackground(final View view) { final View rootView = getActivity().findViewById(R.id.sliding_layout); ViewUtils.afterViewGlobalLayout(new ViewUtils.ViewRunnable(rootView) { @Override/*from w w w . j a v a2s .c om*/ public void run() { Bitmap bm = Bitmap.createBitmap(rootView.getWidth(), rootView.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bm); rootView.draw(canvas); bm = Bitmap.createScaledBitmap(bm, bm.getWidth() / 4, bm.getHeight() / 4, true); bm = BlurTransformation.staticTransform(bm, 25f); ImageView bgImageView = (ImageView) view.findViewById(R.id.background); bgImageView.setImageBitmap(bm); } }); }
From source file:com.tsoliveira.android.listeners.DragDropTouchListener.java
private Bitmap copyViewAsBitmap(View v) { //Clear ripple effect to not get into screenshot, // need something more clever here if (v instanceof FrameLayout) { FrameLayout frameLayout = (FrameLayout) v; Drawable foreground = frameLayout.getForeground(); if (foreground != null) foreground.setVisible(false, false); } else {//from www . jav a2 s .c o m if (v.getBackground() != null) v.getBackground().setVisible(false, false); } Bitmap bitmap = Bitmap.createBitmap(v.getMeasuredWidth(), v.getMeasuredHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); v.draw(canvas); return bitmap; }
From source file:com.yk.notification.util.BitmapUtil.java
/** * View?Bitmap/*w w w. j a va 2s . co m*/ * * @param view * View * @return Bitmap */ public static Bitmap getBitmapFromView(View view) { Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); view.layout(view.getLeft(), view.getTop(), view.getRight(), view.getBottom()); view.draw(canvas); return bitmap; }
From source file:com.s8launch.cheil.facetracker.MultiTrackerActivity.java
public Bitmap getBitmapFromView(View view) { view.setBackgroundColor(Color.TRANSPARENT); //Define a bitmap with the same size as the view Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); //Bind a canvas to it Canvas canvas = new Canvas(returnedBitmap); //Get the view's background Drawable bgDrawable = view.getBackground(); if (bgDrawable != null) //has background drawable, then draw it on the canvas bgDrawable.draw(canvas);/*w w w .j a v a 2 s. com*/ else //does not have background drawable, then draw white background on the canvas canvas.drawColor(Color.WHITE); // draw the view on the canvas view.draw(canvas); //return the bitmap return returnedBitmap; }
From source file:android.widget.PinnedHeaderListView.java
private void drawHeader(final Canvas canvas, final PinnedHeader header, final long currentTime) { if (header.animating) { final int timeLeft = (int) (header.targetTime - currentTime); if (timeLeft <= 0) { header.y = header.targetY;// w w w . j a va 2 s. co m header.visible = header.targetVisible; header.animating = false; } else header.y = header.targetY + (header.sourceY - header.targetY) * timeLeft / mAnimationDuration; } if (header.visible) { final View view = header.view; final int saveCount = canvas.save(); final int translateX = ViewUtil.isViewLayoutRtl(this) ? getWidth() - mHeaderPaddingStart - view.getWidth() : mHeaderPaddingStart; canvas.translate(translateX, header.y); if (header.state == FADING) { mBounds.set(0, 0, view.getWidth(), view.getHeight()); canvas.saveLayerAlpha(mBounds, header.alpha, Canvas.ALL_SAVE_FLAG); } view.draw(canvas); canvas.restoreToCount(saveCount); } }
From source file:org.runbuddy.tomahawk.ui.fragments.ContextMenuFragment.java
private void setupBlurredBackground(final View view) { final View rootView = getActivity().findViewById(R.id.sliding_layout); ViewUtils.afterViewGlobalLayout(new ViewUtils.ViewRunnable(rootView) { @Override//from w w w .j a v a 2 s . c o m public void run() { Bitmap bm = Bitmap.createBitmap(rootView.getWidth(), rootView.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bm); rootView.draw(canvas); bm = Bitmap.createScaledBitmap(bm, bm.getWidth() / 4, bm.getHeight() / 4, true); bm = new BlurTransformation(getContext(), 25).transform(bm); ImageView bgImageView = (ImageView) view.findViewById(R.id.background); bgImageView.setImageBitmap(bm); } }); }
From source file:com.cloverstudio.spika.CameraCropActivity.java
/** * Get the image from container - it is already cropped and zoomed If the * image is smaller than container it will be black color set aside * *///from w ww .jav a 2 s . c o m private Bitmap getBitmapFromView(View view) { Bitmap returnedBitmap = Bitmap.createBitmap(crop_container_size, crop_container_size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(returnedBitmap); Drawable bgDrawable = view.getBackground(); if (bgDrawable != null) bgDrawable.draw(canvas); else canvas.drawColor(Color.BLACK); view.draw(canvas); return returnedBitmap; }
From source file:com.devbrackets.android.recyclerext.decoration.ReorderDecoration.java
/** * Generates the Bitmap that will be used to represent the view being dragged across the screen * * @param view The view to create the drag bitmap from * @return The bitmap representing the drag view *//* www. java 2s . co m*/ private BitmapDrawable createDragBitmap(View view) { floatingItemStartingBounds = new Rect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom()); floatingItemBounds = new Rect(floatingItemStartingBounds); Bitmap bitmap = Bitmap.createBitmap(floatingItemStartingBounds.width(), floatingItemStartingBounds.height(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); view.draw(canvas); BitmapDrawable retDrawable = new BitmapDrawable(view.getResources(), bitmap); retDrawable.setBounds(floatingItemBounds); return retDrawable; }
From source file:com.joanzapata.PDFViewActivity.java
public byte[] getBitmapFromView(View view) { // Define a bitmap with the same size as the view Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); // Bind a canvas to it Canvas canvas = new Canvas(returnedBitmap); // Get the view's background Drawable bgDrawable = view.getBackground(); if (bgDrawable != null) // has background drawable, then draw it on the canvas bgDrawable.draw(canvas);//from ww w . ja va 2s .co m else // does not have background drawable, then draw white background on // the canvas canvas.drawColor(Color.WHITE); // draw the view on the canvas view.draw(canvas); ByteArrayOutputStream stream = new ByteArrayOutputStream(); returnedBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); byte[] byteArray = stream.toByteArray(); return byteArray; }
From source file:com.github.shareme.gwsmaterialuikit.library.advancerv.draggable.DraggingItemDecorator.java
private Bitmap createDraggingItemImage(View v, NinePatchDrawable shadow) { int width = v.getWidth() + mShadowPadding.left + mShadowPadding.right; int height = v.getHeight() + mShadowPadding.top + mShadowPadding.bottom; final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); if (shadow != null) { shadow.setBounds(0, 0, width, height); shadow.draw(canvas);// www . ja v a2 s . c o m } final int savedCount = canvas.save(Canvas.CLIP_SAVE_FLAG | Canvas.MATRIX_SAVE_FLAG); // NOTE: Explicitly set clipping rect. This is required on Gingerbread. canvas.clipRect(mShadowPadding.left, mShadowPadding.top, width - mShadowPadding.right, height - mShadowPadding.bottom); canvas.translate(mShadowPadding.left, mShadowPadding.top); v.draw(canvas); canvas.restoreToCount(savedCount); return bitmap; }