convert View To Bitmap - Android User Interface

Android examples for User Interface:View Bitmap

Description

convert View To Bitmap

Demo Code


//package com.java2s;
import android.graphics.Bitmap;

import android.view.View;

public class Main {

    public static Bitmap convertViewToBitmap(View v) {
        v.setDrawingCacheEnabled(true);//w w  w . j av a 2  s  . c o m
        v.measure(View.MeasureSpec.makeMeasureSpec(0,
                View.MeasureSpec.UNSPECIFIED), View.MeasureSpec
                .makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
        v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());

        v.buildDrawingCache(true);
        Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
        v.setDrawingCacheEnabled(false); // clear drawing cache
        return b;
    }
}

Related Tutorials