0

This is my code to rotate a image. Image is already down sampled and decoded. But this throws an exception because it creates an additional copy of the image. How can I generate the image safely?

 public Bitmap rotateBitmap(Bitmap image, int angle) {
        if (image != null) {

            Matrix matrix = new Matrix();
            matrix.postRotate(angle, (image.getWidth()) / 2,
                    (image.getHeight()) / 2);

            return Bitmap.createBitmap(image, 0, 0, image.getWidth(),
                    image.getHeight(), matrix, true);
        }
        return null;
    }
pats
  • 1,273
  • 2
  • 20
  • 43
  • Check this http://stackoverflow.com/questions/11275650/how-to-increase-heap-size-of-an-android-application – Anton Shkurenko Dec 09 '15 at 13:21
  • And also call Bitmap#recycle when you don't need it. – Anton Shkurenko Dec 09 '15 at 13:22
  • 1
    problem is your bitmap size. make sure reuse bitmap variable or use bitmap.recycle(); – Vishal Patel Dec 09 '15 at 13:34
  • 2
    Not strictly an answer, but Android is a minefield when working with Bitmaps. You would be much better-off by using a tested library such as [Picasso](http://square.github.io/picasso/). – Knossos Dec 09 '15 at 13:36
  • 1
    Thanks fore responses. I can recycle the input image to the method once new one is created. But, I dont think that would resolve the issue because memoery issue will be there while rotation is taking place. Is there a different way to get this done, without duplicating the image in memory – pats Dec 09 '15 at 13:59

0 Answers0