Java Code Examples for android.view.View.draw()

The following are Jave code examples for showing how to use draw() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: GitHub   File: DragDropTouchListener.java   Source Code and License Vote up 7 votes
private ImageView copyViewAsImage(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 {
        if (v.getBackground() != null) v.getBackground().setVisible(false, false);
    }


    Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    v.draw(canvas);

    //Drag highlight, usually border
    if (dragHighlight != null) {
        dragHighlight.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
        dragHighlight.draw(canvas);
    }

    ImageView imageView = new ImageView(recyclerView.getContext());
    imageView.setImageBitmap(bitmap);
    return imageView;
}
 
Example 2
Project: QiangHongBao   File: BitmapUtils.java   Source Code and License Vote up 7 votes
/**
 * 从视图创建位图
 * @param view
 * @return
 */
public static Bitmap createBitmapFromView(View view) {
	if (view instanceof ImageView) {
		Drawable drawable = ((ImageView) view).getDrawable();
		if (drawable != null && drawable instanceof BitmapDrawable) {
			return ((BitmapDrawable) drawable).getBitmap();
		}
	}
	view.clearFocus();
	Bitmap bitmap = createBitmapSafely(view.getWidth(),
			view.getHeight(), Bitmap.Config.ARGB_8888, 1);
	if (bitmap != null) {
		synchronized (sCanvas) {
			Canvas canvas = sCanvas;
			canvas.setBitmap(bitmap);
			view.draw(canvas);
			canvas.setBitmap(null);
		}
	}
	return bitmap;
}
 
Example 3
Project: aos-MediaLib   File: ArtworkFactory.java   Source Code and License Vote up 6 votes
public Bitmap createViewBitmap(View view, Layout textLayout, int bitmapWidth, int bitmapHeight, int vertical_align) {
	final int actualBitmapWidth = getPowerOfTwo(bitmapWidth);
	final int actualBitmapHeight = getPowerOfTwo(bitmapHeight);
	Bitmap destBitmap = Bitmap.createBitmap( actualBitmapWidth, actualBitmapHeight, Bitmap.Config.ARGB_8888 );
	destBitmap.eraseColor(Color.TRANSPARENT);

	synchronized (mCanvas) {
		mCanvas.setBitmap(destBitmap);
		mCanvas.save();

		// Center the bitmap horizontally inside the "powerOfTwo" texture bitmap
           mCanvas.translate((actualBitmapWidth - bitmapWidth) / 2, 0);

		// Align vertically depending of the argument
		switch (vertical_align) {
		case ALIGN_BOTTOM:
			mCanvas.translate(0,actualBitmapHeight - bitmapHeight);
			break;
		case ALIGN_TOP:
			break;
		case ALIGN_CENTER:
		default:
			mCanvas.translate(0, (actualBitmapHeight - bitmapHeight) / 2);
		}

		view.draw(mCanvas);
           if (textLayout != null) {
               // Draw the text using the TextLayout if one is provided
               mCanvas.translate(0, (actualBitmapHeight - bitmapHeight) / 2);
               textLayout.draw(mCanvas);
           }

		mCanvas.restore();
	}
	return destBitmap;
}
 
Example 4
Project: Slide-RSS   File: DragSortRecycler.java   Source Code and License Vote up 6 votes
private BitmapDrawable createFloatingBitmap(View v) {
    floatingItemStatingBounds = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
    floatingItemBounds = new Rect(floatingItemStatingBounds);

    Bitmap bitmap = Bitmap.createBitmap(floatingItemStatingBounds.width(),
            floatingItemStatingBounds.height(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    v.draw(canvas);

    BitmapDrawable retDrawable = new BitmapDrawable(v.getResources(), bitmap);
    retDrawable.setBounds(floatingItemBounds);

    return retDrawable;
}
 
Example 5
Project: RLibrary   File: ImageUtils.java   Source Code and License Vote up 6 votes
/**
 * view转Bitmap
 *
 * @param view 视图
 * @return bitmap
 */
public static Bitmap view2Bitmap(View view) {
    if (view == null) return null;
    Bitmap ret = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(ret);
    Drawable bgDrawable = view.getBackground();
    if (bgDrawable != null) {
        bgDrawable.draw(canvas);
    } else {
        canvas.drawColor(Color.WHITE);
    }
    view.draw(canvas);
    return ret;
}
 
Example 6
Project: GitHub   File: HeaderRenderer.java   Source Code and License Vote up 6 votes
/**
 * Draws a header to a canvas, offsetting by some x and y amount
 *
 * @param recyclerView the parent recycler view for drawing the header into
 * @param canvas       the canvas on which to draw the header
 * @param header       the view to draw as the header
 * @param offset       a Rect used to define the x/y offset of the header. Specify x/y offset by setting
 *                     the {@link Rect#left} and {@link Rect#top} properties, respectively.
 */
public void drawHeader(RecyclerView recyclerView, Canvas canvas, View header, Rect offset) {
  canvas.save();

  if (recyclerView.getLayoutManager().getClipToPadding()) {
    // Clip drawing of headers to the padding of the RecyclerView. Avoids drawing in the padding
    Rect clipRect = getClipRectForHeader(recyclerView, header);
    canvas.clipRect(clipRect);
  }

  canvas.translate(offset.left, offset.top);

  header.draw(canvas);
  canvas.restore();
}
 
Example 7
Project: chromium-for-android-56-debug-video   File: ViewUtils.java   Source Code and License Vote up 6 votes
/**
 * Captures a bitmap of a View and draws it to a Canvas.
 */
public static void captureBitmap(View view, Canvas canvas) {
    // Invalidate all the descendants of view, before calling view.draw(). Otherwise, some of
    // the descendant views may optimize away their drawing. http://crbug.com/415251
    recursiveInvalidate(view);
    view.draw(canvas);
}
 
Example 8
Project: GitHub   File: ConvertUtils.java   Source Code and License Vote up 6 votes
/**
 * view转Bitmap
 *
 * @param view 视图
 * @return bitmap
 */
public static Bitmap view2Bitmap(final View view) {
    if (view == null) return null;
    Bitmap ret = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(ret);
    Drawable bgDrawable = view.getBackground();
    if (bgDrawable != null) {
        bgDrawable.draw(canvas);
    } else {
        canvas.drawColor(Color.WHITE);
    }
    view.draw(canvas);
    return ret;
}
 
Example 9
Project: boohee_v5.6   File: BitmapUtil.java   Source Code and License Vote up 6 votes
public static Bitmap loadBitmapFromView(View v) {
    if (v.getMeasuredHeight() > 0) {
        return null;
    }
    v.measure(MeasureSpec.makeMeasureSpec((int) DensityUtil.getScreenWidth(v.getContext()),
            1073741824), MeasureSpec.makeMeasureSpec(0, 0));
    Bitmap b = Bitmap.createBitmap(v.getMeasuredWidth(), v.getMeasuredHeight(), Config
            .ARGB_8888);
    Canvas c = new Canvas(b);
    v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
    v.draw(c);
    return b;
}
 
Example 10
Project: BoardView   File: BoardView.java   Source Code and License Vote up 6 votes
private Bitmap getBitmapFromView(View v, float scale){
    double radians = 0.0523599f;
    double s = Math.abs(Math.sin(radians));
    double c = Math.abs(Math.cos(radians));
    int width = (int)(v.getHeight()*s + v.getWidth()*c);
    int height = (int)(v.getWidth()*s + v.getHeight()*c);
    Bitmap bitmap = Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.scale(scale,scale);
    v.draw(canvas);
    return bitmap;
}
 
Example 11
Project: BaseCore   File: ImageUtils.java   Source Code and License Vote up 6 votes
/**
 * view转Bitmap
 *
 * @param view 视图
 * @return bitmap
 */
public static Bitmap view2Bitmap(View view) {
    if (view == null) return null;
    Bitmap ret = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(ret);
    Drawable bgDrawable = view.getBackground();
    if (bgDrawable != null) {
        bgDrawable.draw(canvas);
    } else {
        canvas.drawColor(Color.WHITE);
    }
    view.draw(canvas);
    return ret;
}
 
Example 12
Project: aftercare-app-android   File: DCUtils.java   Source Code and License Vote up 6 votes
public static Bitmap loadBitmapFromView(View v) {
    Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawColor(Color.WHITE);
    v.draw(canvas);
    return bitmap;
}
 
Example 13
Project: BlurPopupWindow   File: BlurPopupWindow.java   Source Code and License Vote up 6 votes
BlurTask(View sourceView, int statusBarHeight, int navigationBarheight, BlurPopupWindow popupWindow, BlurTaskCallback blurTaskCallback) {
    mContextRef = new WeakReference<>(sourceView.getContext());
    mPopupWindowRef = new WeakReference<>(popupWindow);
    mBlurTaskCallback = blurTaskCallback;

    int height = sourceView.getHeight() - statusBarHeight - navigationBarheight;
    if (height < 0) {
        height = sourceView.getHeight();
    }

    Drawable background = sourceView.getBackground();
    mSourceBitmap = Bitmap.createBitmap(sourceView.getWidth(), height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(mSourceBitmap);
    int saveCount = 0;
    if (statusBarHeight != 0) {
        saveCount = canvas.save();
        canvas.translate(0, -statusBarHeight);
    }
    if (popupWindow.getBlurRadius() > 0) {
        if (background == null) {
            canvas.drawColor(0xffffffff);
        }
        sourceView.draw(canvas);
    }
    if (popupWindow.getTintColor() != 0) {
        canvas.drawColor(popupWindow.getTintColor());
    }
    if (statusBarHeight != 0 && saveCount != 0) {
        canvas.restoreToCount(saveCount);
    }
}
 
Example 14
Project: Watermark   File: MarkPresenter.java   Source Code and License Vote up 6 votes
public Bitmap getBitmapByView(View v) {
    Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(),
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    v.draw(canvas);
    return bitmap;
}
 
Example 15
Project: xwallet   File: CircleLayout.java   Source Code and License Vote up 6 votes
private void drawChild(Canvas canvas, View child, LayoutParams lp) {
    mSrcCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
    mDstCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);

    mSrcCanvas.save();

    int childLeft = child.getLeft();
    int childTop = child.getTop();
    int childRight = child.getRight();
    int childBottom = child.getBottom();

    mSrcCanvas.clipRect(childLeft, childTop, childRight, childBottom, Op.REPLACE);
    mSrcCanvas.translate(childLeft, childTop);

    child.draw(mSrcCanvas);

    mSrcCanvas.restore();

    mXferPaint.setXfermode(null);
    mXferPaint.setColor(Color.BLACK);

    float sweepAngle = (lp.endAngle - lp.startAngle) % 361;

    mDstCanvas.drawArc(mBounds, lp.startAngle, sweepAngle, true, mXferPaint);
    mXferPaint.setXfermode(mXfer);
    mDstCanvas.drawBitmap(mSrc, 0f, 0f, mXferPaint);

    canvas.drawBitmap(mDst, 0f, 0f, null);
}
 
Example 16
Project: OSchina_resources_android   File: TweetShareFragment.java   Source Code and License Vote up 6 votes
private static Bitmap create(View v) {
    try {
        int w = v.getWidth();
        int h = v.getHeight();
        Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);
        Canvas c = new Canvas(bmp);
        c.drawColor(Color.WHITE);
        v.layout(0, 0, w, h);
        v.draw(c);
        return bmp;
    } catch (OutOfMemoryError error) {
        error.printStackTrace();
        return null;
    }
}
 
Example 17
Project: XFrame   File: XBitmapUtils.java   Source Code and License Vote up 6 votes
/**
 * 从View获取Bitmap
 *
 * @param view View
 * @return Bitmap
 */
public static Bitmap getBitmapFromView(View view) {
    if (view == null) {
        return null;
    }
    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;
}
 
Example 18
Project: Hello-Music-droid   File: PlayTransition.java   Source Code and License Vote up 6 votes
@Override
public void captureStartValues(TransitionValues transitionValues) {
    final View view = transitionValues.view;
    if (view.getWidth() <= 0 || view.getHeight() <= 0) {
        return;
    }
    captureValues(transitionValues);
    Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    view.draw(canvas);
    transitionValues.values.put(PROPERTY_IMAGE, bitmap);
}
 
Example 19
Project: AndroidBasicLibs   File: ViewUtils.java   Source Code and License Vote up 5 votes
public static Bitmap createViewBitmap(View v) {
    Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    v.draw(canvas);
    return bitmap;
}
 
Example 20
Project: boohee_v5.6   File: BitmapHelper.java   Source Code and License Vote up 5 votes
public static Bitmap captureView(View view, int i, int i2) throws Throwable {
    Bitmap createBitmap = Bitmap.createBitmap(i, i2, Config.ARGB_8888);
    view.draw(new Canvas(createBitmap));
    return createBitmap;
}