Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.view.View;

public class Main {

    public static Bitmap takeScreenShot(View view) {
        if (null == view) {
            return null;
        }

        assert view.getWidth() > 0 && view.getHeight() > 0;
        Bitmap.Config config = Bitmap.Config.ARGB_8888;

        Bitmap bitmap = null;
        try {
            bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), config);
            Canvas canvas = new Canvas(bitmap);
            view.draw(canvas);
        } catch (OutOfMemoryError e) {
            e.printStackTrace();
        }

        return bitmap;
    }
}