get Bitmap from ScrollView - Android Graphics

Android examples for Graphics:Bitmap Paint

Description

get Bitmap from ScrollView

Demo Code


//package com.java2s;

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

import android.widget.ScrollView;

public class Main {
    public static Bitmap getBitmapByView(ScrollView scrollView) {
        int h = 0;
        Bitmap bitmap = null;//from ww  w .  j  a  va  2  s . c om

        for (int i = 0; i < scrollView.getChildCount(); i++) {
            h += scrollView.getChildAt(i).getHeight();
            scrollView.getChildAt(i).setBackgroundColor(
                    Color.parseColor("#ffffff"));
        }

        bitmap = Bitmap.createBitmap(scrollView.getWidth(), h,
                Bitmap.Config.RGB_565);
        final Canvas canvas = new Canvas(bitmap);
        scrollView.draw(canvas);
        return bitmap;
    }
}

Related Tutorials