Code example for BufferedInputStream

Methods: decodeStreammarkreset

	 * @param config          You can use this to change the number of bytes per pixel using various bitmap configurations. 
	 * @return A bitmap whose edges are equal to or less than minShrunkEdge in length. 
	public static Bitmap createLightweightScaledBitmapFromStream(InputStream is, int minShrunkWidth, int minShrunkHeight, Bitmap.Config config) {
		BufferedInputStream bis = new BufferedInputStream(is, 32 * 1024);
		try { 
			BitmapFactory.Options options = new BitmapFactory.Options();
			if (config != null) {
				options.inPreferredConfig = config;
			final BitmapFactory.Options decodeBoundsOptions = new BitmapFactory.Options();
			decodeBoundsOptions.inJustDecodeBounds = true;
			BitmapFactory.decodeStream(bis, null, decodeBoundsOptions);
			final int width = decodeBoundsOptions.outWidth;
			final int height = decodeBoundsOptions.outHeight;
			Log.v("Original bitmap dimensions: %d x %d", width, height);
			int sampleRatio = Math.max(width / minShrunkWidth, height / minShrunkHeight);
			if (sampleRatio >= 2) {
				options.inSampleSize = sampleRatio;
			Log.v("Bitmap sample size = %d", options.inSampleSize);
			Bitmap ret = BitmapFactory.decodeStream(bis, null, options);
			Log.d("Sampled bitmap size = %d X %d", options.outWidth, options.outHeight);
			return ret;
		} catch (IOException e) {
			Log.e("Error resizing bitmap from InputStream.", e);
		} finally { 
		return null; 
Stop searching for code, let great code find you!  Add Codota to your java IDE