Save image in BMP 1bit format

#1

Hi,

I want to save image in Bitmap with 1bit depth.
I use EasyBMP library. It’s working well but not very efficient :frowning:

#ifndef PBitmap_h
#define PBitmap_h
#include "EasyBMP.h"
#include "ofMain.h"

static void saveToBitmap1BitByPixel(ofImage &img, string absolutePath){
    
    BMP bmp;
    
    //save in BMP 1 bit depth
    bmp.SetSize(img.getWidth(), img.getHeight());
    bmp.SetBitDepth(1);
    
    RGBApixel px;
    
    for(int y=0; y<img.getHeight(); y++){
        for(int x=0; x<img.getWidth(); x++){

            px.Red = img.getColor(x, y).r;
            px.Green = img.getColor(x, y).g;
            px.Blue = img.getColor(x, y).b;
            bmp.SetPixel(x, y, px);
        }
    }
    
    char pp[1024];
    strcpy(pp, absolutePath.c_str());
    
    bmp.WriteToFile(pp);
    
    
};

#endif /* PBitmap_h */

May be someone else have a more elegant solution ?