Get Bitmap From Name
//package edu.dhbw.andobjviewer.util; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import android.content.res.AssetManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; abstract class BaseFileUtil { protected String baseFolder = null; /* (non-Javadoc) * @see edu.dhbw.andobjviewer.util.FileUtilInterface#getBaseFolder() */ public String getBaseFolder() { return baseFolder; } /* (non-Javadoc) * @see edu.dhbw.andobjviewer.util.FileUtilInterface#setBaseFolder(java.io.File) */ public void setBaseFolder(String baseFolder) { this.baseFolder = baseFolder; } /** * get an reader through it's filename * @param name * @return may be null, in case of an exception */ public abstract BufferedReader getReaderFromName(String name); /** * get a bitmap object through an filename. * @param name * @return may be null, in case of an exception */ public abstract Bitmap getBitmapFromName(String name); } public class AssetsFileUtil extends BaseFileUtil { private AssetManager am; public AssetsFileUtil(AssetManager am) { this.am = am; } @Override public Bitmap getBitmapFromName(String name) { InputStream is = getInputStreamFromName(name); return (is==null)?null:BitmapFactory.decodeStream(is); } @Override public BufferedReader getReaderFromName(String name) { InputStream is = getInputStreamFromName(name); return (is==null)?null:new BufferedReader(new InputStreamReader(is)); } private InputStream getInputStreamFromName(String name) { InputStream is; if(baseFolder != null) { try { is = am.open(baseFolder+name); } catch (IOException e) { e.printStackTrace(); return null; } } else { try { is = am.open(name); } catch (IOException e) { e.printStackTrace(); return null; } } return is; } }