Android Utililty Methods Bitmap Load

List of utility methods to do Bitmap Load

Description

The list of methods to do Bitmap Load are organized into topic(s).

Method

BitmapdownSampleBitmap(Uri uri, Activity act, Boolean needRotate)
down Sample Bitmap
DisplayMetrics displaymetrics = new DisplayMetrics();
act.getWindowManager().getDefaultDisplay()
        .getMetrics(displaymetrics);
Resources r = act.getResources();
int px = (int) TypedValue.applyDimension(
        TypedValue.COMPLEX_UNIT_DIP, 50, r.getDisplayMetrics()); 
int targetWidth = displaymetrics.heightPixels;
int targetHeight = displaymetrics.widthPixels - px;
...
BitmapgetBitmap(Context context, int resId)
get Bitmap
BitmapDrawable drawable = (BitmapDrawable) context.getResources()
        .getDrawable(resId);
return drawable.getBitmap();
BitmapgetBitmap(String photoId)
This method used to get Bitmap From photo id.
final Cursor photo = mSmartAndroidActivity.managedQuery(
        Data.CONTENT_URI, new String[] { Photo.PHOTO }, Data._ID
                + "=?", new String[] { photoId }, null);
final Bitmap photoBitmap;
if (photo.moveToFirst()) {
    byte[] photoBlob = photo.getBlob(photo
            .getColumnIndex(Photo.PHOTO));
    photoBitmap = BitmapFactory.decodeByteArray(photoBlob, 0,
...
BitmapgetBitmapFromAsset(String strName, Context context)
get Bitmap From Asset
try {
    AssetManager assetManager = context.getAssets();
    InputStream inputStream = assetManager.open(strName);
    return BitmapFactory.decodeStream(inputStream);
} catch (IOException e) {
    Toast.makeText(context, "Error in filepath", Toast.LENGTH_SHORT)
            .show();
    e.printStackTrace();
...
BitmapgetBitmapFromInternet(String strName)
get Bitmap From Internet
try {
    URL url = new URL(strName);
    HttpURLConnection connection = (HttpURLConnection) url
            .openConnection();
    connection.setDoInput(true);
    connection.connect();
    InputStream input = connection.getInputStream();
    Bitmap myBitmap = BitmapFactory.decodeStream(input);
...
BitmapgetBitmapFromUri(Context ctxt, Uri selectedImageURI)
get Bitmap From Uri
try {
    InputStream is = ctxt.getContentResolver().openInputStream(
            selectedImageURI);
    is = ctxt.getContentResolver()
            .openInputStream(selectedImageURI);
    Bitmap bitmap = BitmapFactory.decodeStream(is);
    return bitmap;
} catch (FileNotFoundException e) {
...
BitmapgetBitmapFromUrl(String url)
get Bitmap From Url
byte[] bytes = getBytesFromUrl(url);
return byteToBitmap(bytes);
BitmaploadBitmapFromFile(String fileNameWithPath)
load Bitmap From File
Bitmap bitmap = BitmapFactory.decodeFile(fileNameWithPath);
return bitmap;
BitmapdownloadBitmap(URI uri)
download Bitmap
try {
    URLConnection connection = uri.toURL().openConnection();
    connection.connect();
    InputStream is = connection.getInputStream();
    BufferedInputStream bis = new BufferedInputStream(is, 8 * 1024);
    Bitmap bmp = BitmapFactory.decodeStream(bis);
    bis.close();
    is.close();
...
BitmapreturnBitMap(String path)
return Bit Map
URL url = null;
Bitmap bitmap = null;
url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(is);
...