create Bitmap From Scroll View - Android User Interface

Android examples for User Interface:ScrollView

Description

create Bitmap From Scroll View

Demo Code


//package com.java2s;

import android.graphics.Bitmap;

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

import android.graphics.drawable.Drawable;

import android.view.View;

import android.widget.ScrollView;

public class Main {
    public static Bitmap createBitmapFromScrollView(ScrollView scrollView) {
        if (scrollView == null) {
            return null;
        }/*from  www. j  a  v a 2 s .  co  m*/
        int totalHeight = scrollView.getChildAt(0).getHeight();
        int totalWidth = scrollView.getChildAt(0).getWidth();
        Bitmap b = getBitmapFromView(scrollView, totalHeight, totalWidth);
        return b;
    }

    public static Bitmap getBitmapFromView(View view, int totalHeight,
            int totalWidth) {
        Bitmap returnedBitmap = Bitmap.createBitmap(totalWidth,
                totalHeight, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(returnedBitmap);
        Drawable bgDrawable = view.getBackground();
        if (bgDrawable != null)
            bgDrawable.draw(canvas);
        else
            canvas.drawColor(Color.WHITE);
        view.draw(canvas);
        return returnedBitmap;
    }
}

Related Tutorials