BitmapFactory.decodeFile sem memória com imagens 2400x2400

Preciso enviar uma imagem de um arquivo para um servidor. O servidor solicita a imagem em uma resolução de 2400x2400.

O que estou tentando fazer é:

1) Obtenha um Bitmap usando BitmapFactory.decodeFile usando o inSampleSize correto.

2) Comprima a imagem em JPEG com uma qualidade de 40%

3) Codifique a imagem em base64

4) Enviado para o servidor

Não consigo realizar o primeiro passo, ele lança uma exceção de falta de memória. Tenho certeza de que o inSampleSize está correto, mas suponho que mesmo com o inSampleSize o Bitmap seja enorme (cerca de 30 MB no DDMS).

Alguma idéia de como fazer isso? Posso executar essas etapas sem criar um objeto de bitmap? Quero dizer, fazê-lo no sistema de arquivos em vez da memória RAM.

Este é o código atual:

// The following function calculate the correct inSampleSize
Bitmap image = Util.decodeSampledBitmapFromFile(imagePath, width,height);   
// compressing the image
ByteArrayOutputStream baos = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 40, baos);
// encode image
String encodedImage = Base64.encodeToString(baos.toByteArray(),Base64.DEFAULT));


public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
    // Raw height and width of image
    final int height = options.outHeight;
    final int width = options.outWidth;
    int inSampleSize = 1;

    if (height > reqHeight || width > reqWidth) {

        // Calculate ratios of height and width to requested height and width
        final int heightRatio = Math.round((float) height / (float) reqHeight);
        final int widthRatio = Math.round((float) width / (float) reqWidth);

        // Choose the smallest ratio as inSampleSize value, this will guarantee
        // a final image with both dimensions larger than or equal to the
        // requested height and width.
        inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
    }

    return inSampleSize;
}

public static Bitmap decodeSampledBitmapFromFile(String path,int reqWidth, int reqHeight) {

    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(path, options);

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

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

questionAnswers(3)

yourAnswerToTheQuestion