get Bitmap From View by width and height - Android Graphics

Android examples for Graphics:Bitmap Size

Description

get Bitmap From View by width and height

Demo Code

/**/*  ww w . ja v a  2s .  co  m*/
 * This file is part of Owlet.
 * 
 * Owlet is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *  
 * Owlet is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *  
 * You should have received a copy of the GNU General Public License
 * along with Owlet.  If not, see <http://www.gnu.org/licenses/>.
 */
//package com.java2s;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.view.View;

public class Main {
    public static Bitmap getBitmapFromView(View v, int w, int h) {
        Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(b);
        v.layout(0, 0, w, h);
        v.draw(c);
        return b;
    }
}

Related Tutorials