Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Convert current screen to bitmap

I would like to convert a screen of my app and convert it into a Bitmap. I already know how to convert a view into a bitmap, but that's not what I want as my screen is made up of many fragments. Thus I'd like to be able to take the screen and convert it into a bitmap... Help is highly appreciated thanks.

like image 778
Adifyr Avatar asked Apr 25 '14 13:04

Adifyr


1 Answers

You could use something like this and pass the layout as a view ;)

public Bitmap takeScreenShot(View view) {
        // configuramos para que la view almacene la cache en una imagen
        view.setDrawingCacheEnabled(true);
        view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
        view.buildDrawingCache();

        if(view.getDrawingCache() == null) return null; // Verificamos antes de que no sea null

        // utilizamos esa cache, para crear el bitmap que tendra la imagen de la view actual
        Bitmap snapshot = Bitmap.createBitmap(view.getDrawingCache());
        view.setDrawingCacheEnabled(false);
        view.destroyDrawingCache();

        return snapshot;
    }
like image 102
jackgris Avatar answered Oct 18 '22 17:10

jackgris