Android Bitmap Resize zoomBitmapAdjustScreen(Activity activity, String imagePath)

Here you can find the source of zoomBitmapAdjustScreen(Activity activity, String imagePath)

Description

zoom Bitmap Adjust Screen

Declaration

public static Bitmap zoomBitmapAdjustScreen(Activity activity,
            String imagePath) 

Method Source 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) {/*  ww w .  ja  v  a 2  s.c o  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

  1. resizeDrawable(Context context, int resId, int w, int h)
  2. resizePreviewBitmap(Bitmap bm, int width, int height)
  3. smallImage(Bitmap bitmap, int Width, int Height)
  4. zoomBitmap(Bitmap bgimage, int newWidth, int newHeight)
  5. zoomBitmap(Bitmap bitmap, int width, int height)
  6. zoomImage(Bitmap bgimage, int newWidth, int newHeight)
  7. getResizedBitmap(Bitmap bm, int newHeight, int newWidth)
  8. getResizedBitmap(Bitmap bm, int maxX, int maxY, double maxRatio)
  9. getSafeResizingBitmap(String strImagePath, int nMaxResizedWidth, int nMaxResizedHeight, boolean checkOrientation)