Java tutorial
//package com.java2s; import android.content.Context; import android.graphics.BitmapFactory; public class Main { /** * @param imagePath * @return */ public static int[] getActualImageDimension(String imagePath) { int[] imageSize = new int[2]; BitmapFactory.Options decodeOptions = new BitmapFactory.Options(); // If we have to resize this image, first get the natural bounds. decodeOptions.inJustDecodeBounds = true; BitmapFactory.decodeFile(imagePath, decodeOptions); int actualWidth = decodeOptions.outWidth; int actualHeight = decodeOptions.outHeight; imageSize[0] = actualWidth; imageSize[1] = actualHeight; return imageSize; } /** * @param imageResId * @return */ public static int[] getActualImageDimension(Context context, int imageResId) { int[] imageSize = new int[2]; BitmapFactory.Options decodeOptions = new BitmapFactory.Options(); // If we have to resize this image, first get the natural bounds. decodeOptions.inJustDecodeBounds = true; BitmapFactory.decodeResource(context.getResources(), imageResId, decodeOptions); int actualWidth = decodeOptions.outWidth; int actualHeight = decodeOptions.outHeight; imageSize[0] = actualWidth; imageSize[1] = actualHeight; return imageSize; } }