Android Bitmap Load getBitmapFromRes(Context context, int resId)

Here you can find the source of getBitmapFromRes(Context context, int resId)

Description

get Bitmap From Res

License

Open Source License

Declaration

public static Bitmap getBitmapFromRes(Context context, int resId) 

Method Source Code

//License from project: Open Source License 

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import org.ixming.android.utils.FrameworkLog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;

public class Main{
    static final String TAG = "sharebind_bitmaputil";
    public static Bitmap getBitmapFromRes(Context context, int resId) {
        Bitmap bitmap = null;/*from   w  w w  .  j a  v a2  s  .com*/
        try {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inPreferredConfig = Config.RGB_565;
            options.inPurgeable = true;
            options.inInputShareable = true;
            bitmap = BitmapFactory.decodeResource(context.getResources(),
                    resId, options);
        } catch (Exception e) {
            bitmap = null;
            FrameworkLog.e(TAG,
                    "getBitmapFromRes Exception: " + e.getMessage());
        }
        return bitmap;
    }
}

Related

  1. getBitmap(String url, Context context, String newPicName)
  2. getBitmapFromAsset(Context context, String strName)
  3. getBitmapFromFile(File file)
  4. getBitmapFromFile(String filePath)
  5. getBitmapFromFileInputStream(FileInputStream is)
  6. getFromUrl(String url)
  7. getImageFromUri(Context ctx, Uri uri, int reqWidth, int reqHeight)
  8. getNetBitmap(String strUrl, File file, Context context, File file2)
  9. loadBitmap(Activity activity, int resId, ImageView imageView, int reqWidth, int reqHeight)