Returns a bitmap showing a screenshot of the view passed in. - Android User Interface

Android examples for User Interface:View Bitmap

Description

Returns a bitmap showing a screenshot of the view passed in.

Demo Code


//package com.java2s;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.view.View;

public class Main {
    /**//from w w w .  ja v a2  s  .com
     * Returns a bitmap showing a screenshot of the view passed in.
     */
    public static Bitmap getBitmapFromView(View fromView) {

        if (fromView == null || fromView.getWidth() == 0
                || fromView.getHeight() == 0) {
            return null;
        }
        Bitmap bitmap = Bitmap.createBitmap(fromView.getWidth(),
                fromView.getHeight(), Bitmap.Config.ARGB_4444);
        Canvas canvas = new Canvas(bitmap);
        fromView.draw(canvas);
        return bitmap;
    }
}

Related Tutorials