Skip to content Skip to sidebar Skip to footer

Android: Decode Bitmap From Stream

I have this code to get bitmaps from the user external storage /** * Get bitmap from input stream * @param is * @param reqWidth * @param reqHeight * @return Bitmap */ pub

Solution 1:

publicstatic Bitmap decodeSampleBitmapFromFile(String filePath, int reqWidth,
        int reqHeight) {

    // First decode with inJustDecodeBounds=true to check dimensionsfinal BitmapFactory.Optionsoptions=newBitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(filePath,options);

    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, reqWidth,reqHeight);

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeFile(filePath,options);
}

use the above static method to get bitmap from the external storage

Give the filePath ..... correctly

Post a Comment for "Android: Decode Bitmap From Stream"