0

I have the following code which i took from another application

    public static Bitmap createBitMap(DicomObject dcmObj) {
    short[] image = dcmObj.getShorts(Integer.parseInt("7FE00010", 16));
    float wc = dcmObj.getFloat(Integer.parseInt("00281050", 16));
    float ww = dcmObj.getFloat(Integer.parseInt("00281051", 16));

    Bitmap bitMap = Bitmap.createBitmap(dcmObj.getInt(Tag.Columns), dcmObj
            .getInt(Tag.Rows), Bitmap.Config.ARGB_8888);
            bitMap.copyPixelsFromBuffer(LocalImport.makeBuffer((localImport
            .applyWindowing(image, wc, ww)), dcmObj.getInt(Tag.Columns),
            dcmObj.getInt(Tag.Rows)));
    return bitMap;
}

What I am trying to do is load few Dicom images from the SD Card read the attributes and display them in a grid. The above function works fine with the application but when i integrate the same code to my application it crashes. I tried debugging, but the values of the variables are the same.

Tim
  • 35,413
  • 11
  • 95
  • 121
Preethi
  • 154
  • 14
  • Just found out that if i modify the parameters of Bitmap bitMap = Bitmap.createBitmap(dcmObj.getInt(Tag.Columns), dcmObj .getInt(Tag.Rows), Bitmap.Config.ARGB_8888); to Bitmap bitMap = Bitmap.createBitmap(dcmObj.getInt(Tag.Columns)-100, dcmObj .getInt(Tag.Rows)-100, Bitmap.Config.ARGB_8888); the crash doesnt occur, but the images are not good. the crash can also be avoided by changing the config to Config.RGB_565, but the images loaded are distorted. – Preethi May 09 '12 at 08:37
  • You need to reduce the size of your images. When you resize it, you should do it by a power of 2, so half it, quarter it etc. That will give you the highest quality resize. – David Scott May 09 '12 at 10:00
  • Thanks @DavidScott. The crash doesnt occur, but i get blank images in the grid view. :( – Preethi May 09 '12 at 10:23

2 Answers2

0

Until changes are made to Android, the only way to allocate buffers larger than the VM limit is to allocate them in native code. In native code you can allocate as much memory as is physically available to the linux system underneath Android. I've tested this with my own applications and have allocated bitmaps larger than 150MB. Managing bitmaps in native code will then necessitate writing code which renders "views" of the bitmap into a display-sized image that is managed by Java.

BitBank
  • 8,500
  • 3
  • 28
  • 46
  • Thanks @BitBank, but i am not sure if i understood what you said..sorry :( i am a newbie in this field. but i am searching through to understand about native code. anyways.. i suspect memory leak to be the issue in case of my code. but i cant find out where or how. – Preethi May 10 '12 at 04:40
  • When working with large bitmaps, it's easy to exceed the VM memory limit. A RGB888 bitmap of 3000x3000 pixels will exceed the limit (3000x3000x4bytes=36MB). Native code (NDK - C/C++/ASM) can call the lower level memory allocation functions and access all of the memory of the phone). – BitBank May 10 '12 at 04:58
0

the crash was because the animations in the main ui was taking up lots of memory. the Sample application i had copied the code dint have any animations.

guess increasing the size of the memory allocated in the emulator can solve the issue(dint try it out yet).

But atleast i know its not because of any deallocations i hadnt done or logical errors..

Thanks all for the help :)

Preethi
  • 154
  • 14