0

I am trying to load a spritesheet image as bitmap, the image resolution is 3598 x 3598 and its size is 1.21MB. But when I try to load it from following code

AssetManager assets = this.getAssets();
try {
        InputStream inputStream = assets.open("spritesheet.png");
        BufferedInputStream bufferedStream = new BufferedInputStream(inputStream);
        Bitmap bitMap = BitmapFactory.decodeStream(bufferedStream);
} catch (Exception e) {}

I am getting OOM (Out of Memory) exception :'(, Please guide what can I do??

makki
  • 2,097
  • 3
  • 23
  • 34

1 Answers1

1

You should reduce the size of your sprite sheet. Your trying to load 3598 x 3598 x 8 bytes into memory... Thats a lot.

Perhaps you could split it up into smaller more manageable parts?

Warpzit
  • 27,966
  • 19
  • 103
  • 155
  • Thanks for your quick response, can you share, how much resolution or size is acceptable? – makki Jul 30 '12 at 10:10
  • That is hardware dependent :S but in general you should aim for something within the screen dimensions eg. 480x800 for a hdpi phone. But if you are going to have all the bitmap sprites in memory at one time it will probably still give you issues. You should try to minimize the continuous memory usage . – Warpzit Jul 30 '12 at 10:17
  • I'm pretty sure that some sprites only need to be loaded once in a while, these sprites doesn't need to be in memory all the time and could be loaded when they are needed. – Warpzit Jul 30 '12 at 10:18
  • actually I want to run animation using sequence of images, I made sprite sheet of these images, each image is of 256x256 resolution and size in range (1.61 - 25 KB). The count of images are 188. So I just want to display 256x256 res image at a time. But what I am trying to do is, Load the spritesheet image once and get the frames as required. – makki Jul 30 '12 at 10:24
  • Thanks @Warpzit, searching hard but still no luck :(` – makki Jul 30 '12 at 13:07
  • You can't fix it by increasing memory. You need to either use simpler animation, use a video or get the images as they are needed instead of having them all in memory. – Warpzit Jul 30 '12 at 13:20
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/14632/discussion-between-makki-and-warpzit) – makki Jul 30 '12 at 13:26