Example usage for android.view View draw

List of usage examples for android.view View draw

Introduction

In this page you can find the example usage for android.view View draw.

Prototype

@CallSuper
public void draw(Canvas canvas) 

Source Link

Document

Manually render this view (and all of its children) to the given Canvas.

Usage

From source file:com.bobomee.android.common.util.ScreenUtil.java

/**
 * http://stackoverflow.com/questions/9791714/take-a-screenshot-of-a-whole-view
 */// w  w w .ja  va  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:com.simas.vc.helpers.Utils.java

public static Bitmap screenshot2(View v) {
    Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(b);
    v.draw(canvas);

    return b;//from  www  .  j a  va 2 s .  c  o m
}

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);/*from ww  w .j av a 2  s  .co m*/
    v.draw(c);
    return b;
}

From source file:com.mobshep.mobileshepherd.UDataLeakage1.java

public static Bitmap captureScreen(View v) {

    Bitmap screenshot = null;/*from   ww w .  ja  v  a2  s .  c  o m*/
    try {

        if (v != null) {

            screenshot = Bitmap.createBitmap(v.getMeasuredWidth(), v.getMeasuredHeight(),
                    Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(screenshot);
            v.draw(canvas);
        }

    } catch (Exception e) {
        Log.d("ScreenShotActivity", "Failed to capture screenshot because:" + e.getMessage());
    }

    return screenshot;
}

From source file:Main.java

public static Bitmap drawViewToBitmap(View view, int width, int height, float translateX, float translateY,
        int scaleRatio) {
    float scale = 1f / scaleRatio;
    int bmpWidth = (int) (width * scale - translateX / scaleRatio);
    int bmpHeight = (int) (height * scale - translateY / scaleRatio);
    Bitmap dest = Bitmap.createBitmap(bmpWidth, bmpHeight, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(dest);
    c.translate(-translateX / scaleRatio, -translateY / scaleRatio);
    if (scaleRatio > 1) {
        c.scale(scale, scale);/* w ww  .j a v a  2 s  . c o m*/
    }
    view.draw(c);
    return dest;
}

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);//  w ww .  j  a va  2 s  . c  om
    v.draw(c);

    Log.d("artbook", "load bitmap time: " + (System.currentTimeMillis() - time));
    return b;
}

From source file:de.vanita5.twittnuker.util.SwipebackActivityUtils.java

/**
 * /*from   w  w w  .j a  va  2s.co m*/
 * May cause OutOfMemoryError
 * 
 * @param activity
 * @param cacheQuality
 * @return Activity screenshot
 */
private static Bitmap getActivityScreenshotInternal(final Activity activity, final int cacheQuality) {
    if (activity == null)
        return null;
    final Window w = activity.getWindow();
    final View view = w.getDecorView();
    final int width = view.getWidth(), height = view.getHeight();
    if (width <= 0 || height <= 0)
        return null;
    final Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);
    final Rect frame = new Rect();
    view.getWindowVisibleDisplayFrame(frame);
    // Remove window background behind status bar.
    final Canvas c = new Canvas(b);
    view.draw(c);
    final Paint paint = new Paint();
    paint.setColor(Color.TRANSPARENT);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    c.drawRect(frame.left, 0, frame.right, frame.top, paint);
    return b;
}

From source file:Main.java

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();
        }//from w  w w  . j a  va 2s  .  co m
    }
    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;
}

From source file:Main.java

public static Bitmap createScreenshot4(View view, int thumbnailWidth, int thumbnailHeight) {
    if (view != null) {
        Bitmap mCapture;//from w w w .java 2s  .  c om
        try {
            mCapture = Bitmap.createBitmap(thumbnailWidth, thumbnailHeight, Bitmap.Config.RGB_565);
        } catch (OutOfMemoryError e) {
            return null;
        }
        Canvas c = new Canvas(mCapture);
        Paint transPainter = new Paint();
        transPainter.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
        c.drawRect(0, 0, mCapture.getWidth(), mCapture.getHeight(), transPainter);
        try {
            view.draw(c);
        } catch (Exception e) {
        }
        return mCapture;
    }
    return null;
}

From source file:com.android.messaging.ui.animation.ViewGroupItemVerticalExplodeAnimation.java

/**
 * Take a snapshot of the given review, return a Bitmap object that's owned by the caller.
 */// w w w  .java2  s .c  om
static Bitmap snapshotView(final View view) {
    // Save the content of the view into a bitmap.
    final Bitmap viewBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    // Strip the view of its background when taking a snapshot so that things like touch
    // feedback don't get accidentally snapshotted.
    final Drawable viewBackground = view.getBackground();
    ImageUtils.setBackgroundDrawableOnView(view, null);
    view.draw(new Canvas(viewBitmap));
    ImageUtils.setBackgroundDrawableOnView(view, viewBackground);
    return viewBitmap;
}