C++ Bitmap Library

 www.partow.net  .: Home :.   .: Links :.   .: Search :.   .: Contact :. 


The C++ Bitmap Library consists of simple, robust, optimized and portable processing routines for the 24-bit per pixel bitmap image format.


The library has the following capabilities:

  • Read/Write 24-bit Bitmap Images
  • Pixel, row or level level batch editing
  • Color conversions (RGB,YCbCr) in byte and floating values
  • Highly optimized subsample and upsample (resizing)
  • Various color maps (1000 levels - autumn, copper, gray, hot, hsv, jet, prism, vga, yarg)
  • Texture generation (checkered pattern, plasma)
  • Graphics drawing interface (line, line-segment, rectangle, triangle, quadix, horizontal and vertical line-segments, ellipse, circle, plot pixel, pen width, pen color)
  • PSNR and Image comparisons
  • Single header file solution requires no installation or building

C++ Bitmap Library License

Free use of the C++ Bitmap Library is permitted under the guidelines and in accordance with the most current version of the "Common Public License."


The C++ Bitmap Library implementation is compatible with the following C++ compilers:

  • GNU Compiler Collection (4.1+)
  • Intel® C++ Compiler (9.x+)
  • Clang/LLVM (1.1+)
  • PGI C++ (10.x+)
  • Microsoft Visual Studio C++ Compiler (7.1+)
  • Comeau C++ Compiler (4.3+)
  • IBM XL C/C++ (10.x+)


Simple Example 1

The following example will open a bitmap image called 'input.bmp' and count the number of pixels that have a red channel value greater than or equal to 111, then proceed to print the count to stdout.

#include <cstdio>
#include "bitmap_image.hpp"

int main()
   bitmap_image image("input.bmp");

   if (!image)
      printf("Error - Failed to open: input.bmp\n");
      return 1;

   unsigned char red;
   unsigned char green;
   unsigned char blue;

   unsigned int total_number_of_pixels = 0;

   const unsigned int height = image.height();
   const unsigned int width  = image.width();

   for (std::size_t y = 0; y < height; ++y)
      for (std::size_t x = 0; x < width; ++x)
         if (red >= 111)

   printf("Number of pixels with red >= 111: %d\n",total_number_of_pixels);
   return 0;

Simple Example 2

The following example will create a bitmap of dimensions 200x200 pixels, set the background color to orange, then proceed to draw a circle centered in the middle of the bitmap of radius 50 pixels and of color red then a rectangle centered in the middle of the bitmap with a width and height of 100 pixels and of color blue. The newly constructed image will then be saved to disk with the name: 'output.bmp'.

#include "bitmap_image.hpp"

int main()
   bitmap_image image(200,200);

   // set background to orange

   image_drawer draw(image);

   draw.circle(image.width() / 2, image.height() / 2,50);



   return 0;

Copyright Arash Partow