Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import android.content.Context;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

public class Main {
    @SuppressWarnings("deprecation")
    public static Drawable getDrawableFromFile(File pngFile, int density) {
        Bitmap bmp = BitmapFactory.decodeFile(pngFile.getPath());
        bmp.setDensity(density);

        return new BitmapDrawable(bmp);
    }

    public static Drawable getDrawableFromFile(Context context, File pngFile, int density) {
        Bitmap bmp = BitmapFactory.decodeFile(pngFile.getPath());
        if (bmp != null)
            bmp.setDensity(density);

        return new BitmapDrawable(context.getResources(), bmp);
    }

    public static Drawable getDrawableFromFile(File pngFile) {

        return Drawable.createFromPath(pngFile.getPath());
    }
}