Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;

import android.content.res.Resources;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import android.graphics.drawable.BitmapDrawable;

public class Main {
    public static BitmapDrawable getBitmapDrawableFromUrl(Resources res, URL trueUrl,
            BitmapFactory.Options mOptions) throws Exception {
        Bitmap bitmap = null;
        FileInputStream mFS = null;
        try {
            mFS = new FileInputStream(trueUrl.getPath());
            bitmap = BitmapFactory.decodeFileDescriptor(mFS.getFD(), null, mOptions);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (mFS != null) {
                mFS.close();
            }
        }
        return new BitmapDrawable(res, bitmap);
    }
}