title: Loading & Saving Bitmap Images In OpenCV (OpenCV Version = 3.1.0)
body: <p>My problem is simple at least as I see, or how I feel about it.</p>
  <p>I tried to load and write <strong>Bitmap</strong> images with <strong>OpenCV</strong> in <strong>C++</strong> and got sucessed in it, my problem is about the way the image is loaded and written.</p>
  <p>Here is the thing: I working on <strong>256-color palette (8bpp)</strong>, trying to edit or add somethings on it, and then I write it or you can say I save it.
  The problem is that the <strong>color palette</strong> before and after loading the image is <strong>not the same</strong>.
  It seems like OpenCV is not just load the image but also change the palette color, in my case it is changed to <strong>RGB color (24bpp)</strong> which cause of an output image with <strong>size 3</strong> x <strong>original image size</strong> after I saved the loaded image.</p>
  <p>My question <strong>is there a way to load it or write without changing image color palette?</strong> if not possible, <strong>is there a way to write it with specific color palette?</strong> so I can specify it to <strong>256-color palette (8bpp)</strong>, if not possible either any possible <strong>converter</strong> will be good (from <strong>RGB color (24bpp)</strong> to <strong>256-color palette (8bpp))</strong>.</p>
  <p>Here is my <strong>code</strong> to load and write the Bitmap image:</p>
  <pre><code>#include &lt;opencv2/opencv.hpp&gt;
  #include &lt;iostream&gt;
  
  using namespace cv;
  
  int main()
  {
      Mat BitImage = imread(&quot;BitImage_Intput.bmp&quot;, -1); // -1 To load image as it is (without changing) but not working.
      imwrite(&quot;BitImage_Output.bmp&quot;, BitImage); // To write or save the image.
      waitKey(0);
      return 0;
  } 
  </code></pre>
  <p>I found this function, <code>imread(&quot;BitImage_Intput.bmp&quot;, CV_8UC1);</code>, It does the job in a side but ruins it on the other side, the color palette not changed but I got a <strong>GRAYSCALE</strong> image (All colors except <strong>white</strong> and <strong>black</strong> are removed or replaced).</p>
  <blockquote>
  <p><a href="https://drive.google.com/file/d/1EV4rvsM7iV5Pl8b0CFc0UkkYvpzbpv_U/view" rel="nofollow noreferrer"><strong>The 256-color palette (8bpp) Bitmap Image</strong></a></p>
  <p><a href="https://drive.google.com/file/d/1lQyeWyp_XcZc36pAI1g69Tjrvz2o8FDf/view" rel="nofollow noreferrer"><strong>The RGB color (24bpp) Bitmap Image</strong></a></p>
  <p><a href="https://drive.google.com/file/d/1y9nGbOYO34EU77f21vKLFXt5iGNF3NVg/view" rel="nofollow noreferrer"><strong>The GRAYSCALE (8bpp) Bitmap Image</strong></a></p>
  </blockquote>