get ScreenShot - Android User Interface

Android examples for User Interface:ScreenShot

Description

get ScreenShot

Demo Code


//package com.java2s;
import java.io.FileOutputStream;
import android.content.Context;
import android.graphics.Bitmap;

import android.view.View;

public class Main {
    public static boolean getScreenShot(Context context, View view,
            String fileName) {//from  w ww .j  a va2 s. c o  m

        view.setDrawingCacheEnabled(true);

        view.buildDrawingCache();

        Bitmap bitmap = view.getDrawingCache();

        if (bitmap != null) {

            try {

                FileOutputStream out = new FileOutputStream(fileName);

                bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);

                return true;
            } catch (Exception e) {

                e.printStackTrace();

            }

        } else {

        }

        return false;
    }
}

Related Tutorials