load Image from Asset and return Drawable - Android App

Android examples for App:Assets Image

Description

load Image from Asset and return Drawable

Demo Code


//package com.java2s;
import java.io.IOException;
import java.io.InputStream;
import android.content.res.AssetManager;
import android.graphics.drawable.Drawable;

public class Main {
    public static Drawable loadImage(String name, AssetManager assetManager) {
        try {//www. j a v a  2 s  .c  o m
            InputStream ims = assetManager.open(name);
            return Drawable.createFromStream(ims, null);
        } catch (IOException ex) {
            //throw new RuntimeException( "Image " + name + " could not be loaded" );
            return null;
        }
    }
}

Related Tutorials