[solved] Convert image to 4bpp hex code

Hi guys

I'm in need of a way to convert color png files to 4bpp hex files. I've spent the day looking around and downloading stuff that says I can do so but nope. I usually use the digole sight but it only converts up to 3bpp and that won't work.

Does any one know of an actual way to convert my color png to 4bb hex array?

Convert the PNG to a 16-colour BMP with IrfanView or similar.
The resultant file consists of a header, 16 color Palette, 4bpp bitmap.

You will be amazed how recognisable a 262000 colour photo looks when reduced to 16 colours.

Of course, this depends on the choice of Palette. By the sound of it, you have no intention of using a Palette. 16 random colours will look horrible.


Well it's the standard palette used by the ili9341 library. I just want to be able to print a 16x16 bit bitmap with up to 8 colors. The function I'm using is called writerect4bpp(). It allows you to print a bitmap of 4 bits per pixel or 16 colors. And the bitmaps can be stored in flash or Progmem.

It works better than storing 7 bitmaps and stacking them. I've been looking at the function and its 4bpp example and the bitmap is done like so.....

0x00, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66,
0x00, 0x11,etc for 16 X 16.

Name the palatte colors before the function so the zero's will be one color, the ones's another color and so on up to six.

Just got done playing around with it. It's going to be painfully tedious to do the bitmaps in that fashion though that's why I was hoping to find a converter so I can copy and paste.

Go on. Only you know what colours are used by your PNG. Only you know what "ili9341 library" you are using.

Yes, of course a 4bpp bitmap means that two Palette colours are stored in a byte. one in each 4-bit nibble. e.g. 0x34 means colour#3 in one pixel, colour #4 in the next pixel.
You appear to want the same colour in two adjacent pixels. e.g. 0x66 means colour #6 in both pixels.


It doesn't really matter which library. I'm just looking for a way to convert my images into 4bpp arrays so I don't have to write them out by hand. If you know some thing please do tell.

I have over 150 character sprites plus 60 something land tiles and 40 something monsters. That's a lot of tedious work.

You have your own monsters. Only you know them.
You will have to deal with them. Perhaps with professional help.

Regarding 16x16 sprites and tiles. You can fit 300 tiles on a 240x320 screen. Or 240x320 PNG or BMP.

IrfanView would convert to the best 16 colour Palette. And create the appropriate 4bpp BMP all in one go. Perhaps 20 seconds of processing.
Your program would use about 40kB of flash to store 300 16x16 "tiles" in a single BMP.

This rules out a Uno. A Mega, Due, Zero, STM32, ... will be fine.
Of course, you could store millions of tiles on a SD and still use a Uno.


For tiles we do something different. I have a tilemap function that lets you store your individual tile bitmaps once in Progmem or flash and then I can call them and place them using an integer array. So cheap on space and allows for massive world maps.

So let's make a Sprite sheet......

Const byte spritesheet[] = {tile1, tile2, tile3}

Now let's make a world map

Const byte world map[] = {16,16, 8, 8,


This library covers most arduino driven boards and I have seperate libraries just for teensy and esp32.


Don't suppose you would have the hex code for invisible color or no color.