get Scaled Screenshot - Android Animation

Android examples for Animation:Scale Animation

Description

get Scaled Screenshot

Demo Code


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

import android.view.View;

public class Main {
    public static Bitmap getScaledScreenshot(final Activity activity,
            int scaleWidth, int scaleHeight, boolean relativeScaleIfTrue) {
        final View someView = activity.findViewById(android.R.id.content);
        final View rootView = someView.getRootView();
        final boolean originalCacheState = rootView.isDrawingCacheEnabled();
        rootView.setDrawingCacheEnabled(true);
        rootView.buildDrawingCache(true);

        final Bitmap original = rootView.getDrawingCache();
        Bitmap scaled = null;//from   w  w  w. ja  va2  s . c o  m
        if (null != original && original.getWidth() > 0
                && original.getHeight() > 0) {
            if (relativeScaleIfTrue) {
                scaleWidth = original.getWidth() / scaleWidth;
                scaleHeight = original.getHeight() / scaleHeight;
            }
            if (scaleWidth > 0 && scaleHeight > 0) {
                scaled = Bitmap.createScaledBitmap(original, scaleWidth,
                        scaleHeight, false);
            }
        }
        if (!originalCacheState) {
            rootView.setDrawingCacheEnabled(false);
        }
        return scaled;
    }
}

Related Tutorials