How to save memory using a lower bitmap palette than supported by the device?

I was hoping to save some memory by creating the Graphics.BufferedBitmap with a lower color depth than what the device supports, e.g. using 16 colors (4bpp) on devices with 64 colors (RGB222).

But what is the correct way to do that?

  1. I took the image and process it with ImageMagick to reduce the colors to 16
  2. I have ensured the image is not truetype but uses palette
  3. I have checked which colors the final image uses. In my case it was reduced to 14 colors. See screenshot:

What is the next step?

1. If I put this into resource file:

2. I specify the palette from ImageMagick in the code:

            buffer = new Graphics.BufferedBitmap({
                :width => width,
                :height => height,
                :palette => [0x0494B7, 0x17ABCA,0x52CAD0,0x75C5CC,0x9ECABE,0xAFCDB4,0xD6D499,0xCED5A8,0xE0DEBA,0x8DC6C6,0xB5E8E1,0xDEE0C4,0xE2E4D3,0xE7F5F6],
                :colorDepth => 4,
                :alphaBlending => 0}) as BufferedBitmap;

3. It looks great on simulator and I can see a lot of memory is saved.

4. But on device I have error: 

5. I have tried to disable the transparency, but it leads to the same error on the device

What is the correct way to do that? Also, I do not expect it to be necessary to copy the the palette in the code, but I could be wrong...

Thanks a lot!

STeN

P.S. Sorry for entering the code with images, when I c&p the code directly the post is rejected by forum for some "Cloudflare security checks"

  • I become obsessed with the issue and despite it was extremely frustrating I spent hours trying to figure how I can make it working. Nothing helped.

    It will be great to find out how to do it as the saving on the 240x240 bitmap when using 4bits instead of 8bits per color is (surprisingly) 28kB

  • You need to use the palette that the device has. For example fr55 has 8 colors so giving it a 4 color palette only works if you only used colors the device has.

    Regarding memory: I don't use buffered bitmaps but if I recall they use the devices' graphic pool memory so you won't see much change in memory usage IMHO. Maybe in the peak memory because the resource you load is smaller?

  • Hi ,

    Thanks a lot! 

    Of course, obviously – I didn’t realize that! I can only use the colors from the built-int palette

    I tried it right away, and it works perfectly. The simulator shows a savings of 28kB when used 16 colors (vs 64 colors), which is a huge deal for e.g. Fenix 5, which has 64 colors, but only 128kB of memory for watch apps. The image pool is CIQ 4.0.0+, so here it cannot be used and all goes to heap, if I understand it correctly.

    Regards,

    STeN