Back to project page Helpers.
The source code is released under:
MIT License
If you think the Android project Helpers listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package at.wrdlbrnft.helpers; /*w w w .j ava 2 s .c om*/ import android.content.Context; import android.content.res.AssetManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import java.io.File; import java.io.InputStream; /** * Created with IntelliJ Idea 13 * User: Xaver * Date: 26/05/14 */ public class BitmapHelper { public static int calculateInSampleSize(BitmapFactory.Options options, float reqWidth, float reqHeight) { final int height = options.outHeight; final int width = options.outWidth; int inSampleSize = 1; if (height > reqHeight || width > reqWidth) { final int halfHeight = height / 2; final int halfWidth = width / 2; // Calculate the largest inSampleSize value that is a power of 2 and keeps both // height and width larger than the requested height and width. while ((halfHeight / inSampleSize) > reqHeight && (halfWidth / inSampleSize) > reqWidth) { inSampleSize *= 2; } } return inSampleSize; } public static BitmapFactory.Options decodeBounds(Context context, int resId) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(context.getResources(), resId, options); options.inJustDecodeBounds = false; return options; } public static BitmapFactory.Options decodeBounds(InputStream stream) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(stream, null, options); options.inJustDecodeBounds = false; return options; } public static BitmapFactory.Options decodeBounds(String path) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(path, options); options.inJustDecodeBounds = false; return options; } }