Convert bmp to C array

If you want to use pictures in C applications you often need to convert them to an array.

What you need:

  1. Gimp
  2. bin2c

Create a new gimp file with your target image size. e.g. 200×200 px

Open the source image, select all, copy. Switch to your created gim file and paste.

Save as bmp. Select your target format in advanced options.

See the following table to find out your target format:

ModelSizeGimp Property
Keil MCB 1700240×320R5 G6 B5

Now run bin2c on command line:

bin2c -o bitmaps.c image.bmp

[crayon lang=”c” title=”bitmaps.c”]

/* Generated by bin2c, do not edit manually */
/* Contents of file image.bmp */
const long int image_bmp_size = 69958;
const unsigned char image_bmp[69958] = {
0x42, 0x4D, 0x46, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x00, 0x00, 0x00, 0x38, 0x00,
0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0xB6, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00,
0x46, 0x03, 0x05, 0x5B, 0x05, 0x5B, 0x05, 0x5B, 0x42, 0x32, 0x46, 0x03, 0x06, 0xAA, 0xC6, 0xD1,

……………….. the other 69910 entries …………………………
};

[/crayon]

according to this your bitmaps.h would look like this (but its not generated by bin2c):

[crayonlang=”c” title=”bitmaps.h”]
#ifndef BITMAPS_H
#define BITMAPS_H
extern unsigned char image_bmp[];
#endif /* BITMAPS_H  */

[/crayon]

Segger provides a bitmap converter that simplifies this process I guess.

If you have found a spelling error, please, notify us by selecting that text and pressing Ctrl+Enter.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Spelling error report

The following text will be sent to our editors: