zoom Bitmap Adjust Screen - Android Graphics

Android examples for Graphics:Bitmap Zoom

Description

zoom Bitmap Adjust Screen

Demo Code


//package com.java2s;

import android.app.Activity;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import android.view.Display;

import android.view.WindowManager;

public class Main {

    public static Bitmap zoomBitmapAdjustScreen(Activity activity,
            String imagePath) {/*from w ww.ja v a 2 s. co  m*/
        Bitmap bm = null;
        BitmapFactory.Options opt = new BitmapFactory.Options();

        opt.inJustDecodeBounds = true;
        bm = BitmapFactory.decodeFile(imagePath, opt);

        int picWidth = opt.outWidth;
        int picHeight = opt.outHeight;

        WindowManager windowManager = activity.getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        int screenWidth = display.getWidth();
        int screenHeight = display.getHeight();

        opt.inSampleSize = 1;
        if (picWidth > picHeight) {
            if (picWidth > screenWidth)
                opt.inSampleSize = picWidth / screenWidth;
        } else {
            if (picHeight > screenHeight)
                opt.inSampleSize = picHeight / screenHeight;
        }

        opt.inJustDecodeBounds = false;
        bm = BitmapFactory.decodeFile(imagePath, opt);
        return bm;
    }
}

Related Tutorials