Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.IOException;

import android.graphics.BitmapFactory;

public class Main {

    public static int[] getImageSize(String filePath) {
        int[] size = new int[2];

        FileInputStream fis = null;
        try {
            fis = new FileInputStream(new File(filePath));

        } catch (FileNotFoundException e) {
            e.printStackTrace();
            size[0] = size[1] = -1;
            return size;
        }
        try {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeStream(fis, null, options);
            size[0] = options.outWidth;
            size[1] = options.outHeight;
        } catch (Exception e) {
            e.printStackTrace();
            size[0] = size[1] = -1;
            return size;
        } finally {
            try {
                if (fis != null) {
                    fis.close();
                    fis = null;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return size;
    }
}