Bmp to c array image file creation

Hello together,

I am new to programming and desperately trying to get an image onto an Arduino.
This should then display the image on a 7 color e-paper from Waveshare. Unfortunately I can't manage to convert a bmp image into a code that looks like this:

const unsigned char gImage_5in65f[13728] PROGMEM = {
  0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x36, 0x6, 0x36, 0x36, 0x36, 0x36, 0x6, 0x36, 0x6, 
  0x36, 0x6, 0x36, 0x6, 0x36, 0x36, 0x0, 0x61, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x6, 0x36, 
  0x6, 0x36, 0x6, 0x36, 0x36, 0x6, 0x36, 0x6, 0x36, 0x6, 0x36, 0x36, 0x36, 0x6, 0x36, 0x11, 
  0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 
  0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x16, 0x2, 0x36, 0x32, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 
0x63, 0x63, 0x63, 0x63, 0x60, 0x23, 0x63, 0x23, 0x11, 0x11, 0x11, 0x11, 0x11, 0x16, 0x3, 0x26, 
0x36, 0x36, 0x36, 0x36, 0x23, 0x63, 0x63, 0x63, 0x63, 0x63, 0x60, 0x63, 0x26, 0x36, 0x2, 0x11, 
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 
0x11, 0x12, 0x11, 0x12, 0x11, 0x21, 0x12, 0x11, 0x21, 0x11, 0x12, 0x11, 0x21, 0x12, 0x11, 0x21, 
0x12, 0x13, 0x12, 0x16, 0x13, 0x12, 0x11, 0x31, 0x21, 0x31, 0x23, 0x12, 0x32, 0x13, 0x23, 0x21, 
0x11, 0x11, 0x31, 0x11, 0x13, 0x11, .......

Can you help me how to convert a bmp image into an array, which I can then use. I have already created a BMP file with the color palette that is on the Waveshare page.
Unfortunately, any online converter from bmp to c array does not give the correct format.

I am getting desperate and would appreciate your help.

Greetings Gerrit

My approach is to write a C or C++ program for a PC, which takes the data and writes it out in the desired format. I recommend the Code::Blocks IDE.

Example:

//  print data table for array initialization.
  printf(" ={");  //array data initialization start
  int j=0;
  for(i=0; i<table_size; i++) {
    j++;
    printf("%d,", table[i]);
    if (j==10) {printf("\r\n"); j=0;}  //add cr/lf every tenth data point
  }
  printf("}\r\n");  //extra "," to remove by editing.

convert a bmp image into an array

Need more information: specify which of the many bmp formats is chosen, and the output format of the array data.

Something like this?:
BIN file to C-code

Try Google on this exact phrase...

Thanks very much for the fast reply.

The Input File ist an *.BMP (Image File), which i created. If found this Instruktion top create:

But then i want to convert the *.BMP File into an c arry, which looks like the Code drin my first code.
They also provided a Programm in the Website to convert the Image into an Array, but they only can create an Image with the size of 600x480 Pixel. But my Image hast a size of 120x120 Pixel.

If you know more then me to convert a Image File into an Array, i appriciate your Help very much.

You can also write a Python script to convert yourself.

Or you use a Hex Viewer, you load the BIN file and export:
HxD has such an "export as C code":
HxD Hex Viewer

Load the BIN and "File" -> "Export" -> "C".
Works.

Unfortunately, there are many options in the BMP header, and many options for the format of the data in the file, so you need to provide all those details.

See this overview: BMP file format - Wikipedia

How did you create this .BMP file? Can you just write out the data as integers?

Oh yes, this is true!:
if you take a BMP file and you display the file as hex (even you convert to C-array): it will have a "header", telling any file reader about the content of such a BMP file (e.g. the pixel format, the colors used etc.).
And the header is not part of the image (they are not pixel values).

So, you have to "decode" the header and find where the real pixel values are located (in the file). Converting also the header is not right (it is not part of the image).

What about this?:
BMP file to C-array

Based on Google search - what about GIMP?:
GIMP to convert BMP to C-array

Just search for similar questions and hints.
Otherwise: get familiar how a BMP file is structured (header, where the pixel values start in file...) and decode yourself (via a Python script, for instance).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.