Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need first to get the number of colors available in the embedded palette. This is available in the DIB Header.</p> <p>Then you can read all color components that contain the palette.</p> <p>You can see all header information like offset to know whereto seek : <a href="http://en.wikipedia.org/wiki/BMP_file_format" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/BMP_file_format</a>.</p> <p>This should work: (Edit: Add code to write in file)</p> <pre><code>FILE *inFile, *outFile; BMPHeader header; BMPImageInfo info; RGB *palette, *p; int i = 0; inFile = fopen("C://in.bmp", "rb"); if( !inFile ) return; if( fread(&amp;header, sizeof(BMPHeader), 1, inFile) != 1 ) return; // Manage error and close file if( fread&amp;info, sizeof(BMPImageInfo), 1, inFile) != 1 ) return; // Manage error and close file if( info.numColors &gt; 0 ) { palette = (RGB*)malloc(sizeof(RGB) * info.numColors); if( fread(palette, sizeof(RGB), info.numColors, inFile) != info.numColors ) return; // manage error and close file } fclose(inFile) // Binary method =&gt; if read later by another computer outFile = fopen("path", "wb"); if( !outFile ) return; if( fwrite(&amp;info.numColors, sizeof(unsigned int), 1, outFile) != 1 ) return; // Manage Error and close file if( fwrite(&amp;palette, sizeof(RGB), info.numColors, outFile) != info.numColors ) return; // Manage error and close file fclose(outFile); // Text method =&gt; if read later by human outFile = fopen("path", "w"); if( !outFile ) return; for( i=0; i&lt;info.numColors; ++i ) { p = &amp;palette[i]; if( fprintf(outFile, "R:%d, G:%d, B:%d\n", p-&gt;red, p-&gt;green, p-&gt;blue) &lt; 0 ) return; // Manage error and close file } fclose(outFile); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload