Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 * Copyright 2014 sailaway(https://github.com/sailaway)
 *
 * Licensed under theGNU GENERAL PUBLIC LICENSE Version 3 (the "License");
 *  Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
 * Everyone is permitted to copy and distribute verbatim copies
 * of this license document, but changing it is not allowed.
 * 
 */

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.IOException;
import java.io.InputStream;

import android.graphics.BitmapFactory;

import android.graphics.Point;

public class Main {
    public static Point getBitmapSize(InputStream is) {
        BitmapFactory.Options opt = new BitmapFactory.Options();
        opt.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(is, null, opt);
        int x = opt.outWidth;
        int y = opt.outHeight;
        Point p = new Point(x, y);
        return p;
    }

    public static Point getBitmapSize(String filepath) {
        File f = new File(filepath);
        Point p = null;
        FileInputStream fs = null;
        try {
            fs = new FileInputStream(f);
            p = getBitmapSize(fs);
        } catch (FileNotFoundException e) {
        } finally {
            if (fs != null) {
                try {
                    fs.close();
                } catch (IOException e) {
                }
            }
        }
        return p;
    }
}