I went through these topics but still didn't find an answer to the following problem.
Android rotate bitmap without making a copy
Android: rotate image without loading it to memory
Rotating images on android. Is there a better way?
JNI bitmap operations , for helping to avoid OOM when using large images
I have a Uri which represents a big image. I need to save a rotated copy of this image to SD card. But when I do
BitmapFactory.decodeStream(contentResolver.openInputStream(uri));
I get an OutOfMemoryError.
What I wanted do do is something like this
    ContentResolver resolver = getContentResolver();
    InputStream inputStream = null;
    FileOutputStream outputStream = null;
    File imageFile = null;
    try {
        inputStream = resolver.openInputStream(uri);
        //I don't know how to apply this matrix to the bytes of InputStream
        Matrix matrix = new Matrix();
        matrix.postRotate(90);
        imageFile = createImageFile();
        outputStream = new FileOutputStream(imageFile);
        byte[] buffer = new byte[1024];
        while (inputStream.read(buffer) != -1) {
            //I'd like to apply the 'matrix' to 'buffer' here somehow but I can't
            //since 'buffer' contains the bytes of the image, not the pixel values of the bitmap
            outputStream.write(buffer);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        Util.closeQuietly(inputStream);
        Util.closeQuietly(outputStream);
    }
What is the solution for this, if any?
 
     
    