get Bitmap From View - Android User Interface

Android examples for User Interface:View Bitmap

Description

get Bitmap From View

Demo Code


//package com.java2s;

import android.graphics.Bitmap;
import android.graphics.Canvas;

import android.view.View;

public class Main {

    public static Bitmap getBitmapFromView(View view, int width, int height) {
        int widthSpec = View.MeasureSpec.makeMeasureSpec(width,
                View.MeasureSpec.EXACTLY);
        int heightSpec = View.MeasureSpec.makeMeasureSpec(height,
                View.MeasureSpec.EXACTLY);
        view.measure(widthSpec, heightSpec);
        view.layout(0, 0, width, height);
        Bitmap bitmap = Bitmap.createBitmap(width, height,
                Bitmap.Config.RGB_565);//from ww w  . j  a  va 2s .c om
        Canvas canvas = new Canvas(bitmap);
        view.draw(canvas);

        return bitmap;
    }
}

Related Tutorials