App
ImgLoader.java
Go to the documentation of this file.
1 package mhr.app.utils;
2 
3 import java.io.IOException;
4 import java.io.InputStream;
5 
6 import android.content.Context;
7 import android.content.res.AssetManager;
8 import android.graphics.Bitmap;
9 import android.graphics.BitmapFactory;
10 
14 public class ImgLoader {
15 
16  protected Context context;
17  protected AssetManager assetManager;
18 
19  public ImgLoader(Context context) {
20  this.context = context;
21  this.assetManager = context.getAssets();
22  }
23 
29  public Bitmap loadAndroidBitmap(String path) {
30  InputStream is = null;
31  Bitmap res = null;
32  try {
33  is = assetManager.open(path);
34  BitmapFactory.Options o = new BitmapFactory.Options();
35  o.inScaled = false;
36  res = BitmapFactory.decodeStream(is, null, o);
37  } catch (IOException e) {
38  return null;
39  } finally {
40  if (is != null) {
41  try {
42  is.close();
43  } catch (IOException e) {
44  return null;
45  }
46  }
47  }
48  return res;
49  }
50 }