Android Bitmap Load getImageFromAssetFile(Context context, String fileName)

Here you can find the source of getImageFromAssetFile(Context context, String fileName)

Description

get image from assert

Parameter

Parameter Description
context a parameter
fileName a parameter

Declaration

public static Bitmap getImageFromAssetFile(Context context,
        String fileName) 

Method Source Code

//package com.java2s;

import java.io.InputStream;
import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class Main {
    /**/*from   w  ww.ja va  2s . c o m*/
     * get image from assert
     * 
     * @param context
     * @param fileName
     * @return
     */
    public static Bitmap getImageFromAssetFile(Context context,
            String fileName) {
        Bitmap image = null;
        try {
            AssetManager am = context.getAssets();
            InputStream is = am.open(fileName);

            BitmapFactory.Options opt = new BitmapFactory.Options();
            opt.inPreferredConfig = Bitmap.Config.RGB_565;
            opt.inPurgeable = true;
            opt.inInputShareable = true;

            image = BitmapFactory.decodeStream(is, null, opt);
            is.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return image;
    }
}

Related

  1. decodeF(File f)
  2. decodeFile(File f, int size)
  3. decodeFromDescriptor( FileDescriptor descriptor)
  4. decodeFromDescriptor( FileDescriptor descriptor, int reqWidth, int reqHeight)
  5. getBitmap(Context c, String uri, int minsizeDP)
  6. downloadImageToSd(String urlSource, String pathDest)
  7. downloadImageToSd(String urlSource, String pathDest, String referer)
  8. getResizedBitmap(Uri imageUri, Activity activity)
  9. downSampleBitmap(Uri uri, Activity act, Boolean needRotate)