@@ -0,0 +1,2129 @@
+package se.embargo.core.graphics;%0D%0A%0D%0Aimport java.io.File;%0D%0Aimport java.io.FileInputStream;%0D%0Aimport java.io.IOException;%0D%0Aimport java.io.InputStream;%0D%0A%0D%0Aimport android.graphics.Bitmap;%0D%0Aimport android.graphics.BitmapFactory;%0D%0A%0D%0Apublic abstract class Bitmaps %7B%0D%0A%09/**%0D%0A%09 * Decodes and sub-samples an image%0D%0A%09 * @param is%09%09Stream to read image from%0D%0A%09 * @param maxWidth%09Max height of returned image%0D%0A%09 * @param maxHeight%09Max width of returned image%0D%0A%09 * @param config%09Bitmap target coding%0D%0A%09 * @return%09%09%09An image constrained by the given bounds, or null on failure%0D%0A%09 */%0D%0A%09public static Bitmap decodeStream(File file, int maxWidth, int maxHeight, Bitmap.Config config) %7B%0D%0A%09%09InputStream is;%0D%0A%0D%0A%09%09// Check the size of the image%0D%0A%09%09BitmapFactory.Options options = new BitmapFactory.Options();%0D%0A%09%09options.inPreferredConfig = config;%0D%0A        options.inJustDecodeBounds = true;%0D%0A%0D%0A%09%09try %7B%0D%0A%09%09%09is = new FileInputStream(file);%0D%0A%09        BitmapFactory.decodeStream(is, null, options);%0D%0A%09%09%7D%0D%0A%09%09catch (IOException e) %7B%0D%0A%09%09%09return null;%0D%0A%09%09%7D%0D%0A        %0D%0A        if (options.outWidth %3C 0 %7C%7C options.outHeight %3C 0) %7B%0D%0A        %09return null;%0D%0A        %7D%0D%0A        %0D%0A        // Figure if sub-sampling should be used%0D%0A        options.inJustDecodeBounds = false;%0D%0A%0D%0A        if (options.outWidth %3E maxWidth) %7B%0D%0A        %09double ratio = (double)options.outWidth / (double)maxWidth;%0D%0A        %09int samples = (int)Math.ceil(ratio);%0D%0A        %09options.inSampleSize = Math.max(samples, options.inSampleSize);%0D%0A        %7D%0D%0A%0D%0A        if (options.outHeight %3E maxHeight) %7B%0D%0A        %09double ratio = (double)options.outHeight / (double)maxHeight;%0D%0A        %09int samples = (int)Math.ceil(ratio);%0D%0A        %09options.inSampleSize = Math.max(samples, options.inSampleSize);%0D%0A        %7D%0D%0A        %0D%0A        // Reset the stream and decode the image%0D%0A%09%09try %7B%0D%0A%09%09%09is = new FileInputStream(file);%0D%0A%09        return BitmapFactory.decodeStream(is, null, options);%0D%0A%09%09%7D%0D%0A%09%09catch (IOException e) %7B%0D%0A%09%09%09return null;%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%0D%0A%09public static Bitmap decodeStream(File file, int maxWidth, int maxHeight) %7B%0D%0A%09%09return decodeStream(file, maxWidth, maxHeight, Bitmap.Config.ARGB_8888);%0D%0A%09%7D%0D%0A%7D%0D%0A

Use bitmap sub-sampling to avoid out-of-memory