Android Bitmap Size Get getBitmapSize(String strImagePath, boolean checkOrientation)

Here you can find the source of getBitmapSize(String strImagePath, boolean checkOrientation)

Description

get Bitmap Size

Declaration

public static BitmapFactory.Options getBitmapSize(String strImagePath,
            boolean checkOrientation) 

Method Source Code

//package com.java2s;

import java.io.IOException;

import android.graphics.BitmapFactory;

import android.media.ExifInterface;

public class Main {
    public static BitmapFactory.Options getBitmapSize(String strImagePath) {
        //==========================================
        // Loaded the temporary bitmap for getting size.
        //==========================================
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        //Bitmap photo = BitmapFactory.decodeFile(strPath, options);
        BitmapFactory.decodeFile(strImagePath, options);

        return options;
    }/*from ww  w.  jav  a2 s. com*/

    public static BitmapFactory.Options getBitmapSize(String strImagePath,
            boolean checkOrientation) {
        //==========================================
        // Loaded the temporary bitmap for getting size.
        //==========================================
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        //Bitmap photo = BitmapFactory.decodeFile(strPath, options);
        BitmapFactory.decodeFile(strImagePath, options);

        if (checkOrientation) {
            int degree = getExifDegree(strImagePath);
            if (degree == 90 || degree == 270) {
                int temp = options.outWidth;
                options.outWidth = options.outHeight;
                options.outHeight = temp;
            }
        }

        return options;
    }

    public static int getExifDegree(String filepath) {
        int degree = 0;
        ExifInterface exif;
        try {
            exif = new ExifInterface(filepath);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return 0;
        }

        if (exif != null) {
            int orientation = exif.getAttributeInt(
                    ExifInterface.TAG_ORIENTATION, -1);

            if (orientation != -1) {
                switch (orientation) {
                case ExifInterface.ORIENTATION_ROTATE_90:
                    degree = 90;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    degree = 180;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    degree = 270;
                    break;
                }
            }
        }
        return degree;
    }
}

Related

  1. calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight)
  2. computeInitialSampleSize( BitmapFactory.Options options, int minSideLength, int maxNumOfPixels)
  3. computeSampleSize(BitmapFactory.Options options, int minSideLength, int maxNumOfPixels)
  4. getBitmapSize(Bitmap bitmap)
  5. getBitmapSize(String strImagePath)