print Screen to Bitmap - Android User Interface

Android examples for User Interface:View Bitmap

Description

print Screen to Bitmap

Demo Code


//package com.java2s;
import java.io.ByteArrayOutputStream;

import android.graphics.Bitmap;

import android.view.View;

public class Main {

    public static byte[] printScreen(View v, int quality) {
        if (quality == -1)
            quality = 100;//???
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        v.setDrawingCacheEnabled(true);/*from   w w w.jav  a2s  . c  o m*/
        v.buildDrawingCache(true);
        Bitmap bitmap = v.getDrawingCache();
        bitmap.compress(Bitmap.CompressFormat.JPEG, quality, baos);
        return baos.toByteArray();
    }

    public static Bitmap printScreen(View v) {
        v.setDrawingCacheEnabled(true);
        v.buildDrawingCache();
        return v.getDrawingCache();
    }
}

Related Tutorials