C++: What's the simplest way to read and write BMP files using C++ on Windows?

后端 未结 7 1644
囚心锁ツ
囚心锁ツ 2020-12-03 12:16

I would like to load a BMP file, do some operations on it in memory, and output a new BMP file using C++ on Windows (Win32 native). I am aware of ImageMagick and it\'s C++ b

7条回答
  •  臣服心动
    2020-12-03 12:22

    I tried CImage as above, but I had a C array full of pixel values that I simply wanted to dump as a BMP (or any other format). CImage has no constructor for that, and I did not want to link MFC (for CBitmap) nor try to fathom IWIC.

    What was easy was CImg:

    #include 
    using namespace cimg_library;
    //...
    void SaveMyData(uint8_t *pxarray, int width, int height)
    {
        CImg img(pxarray, width, height);
        img.save_bmp("sav.bmp");
    }
    

提交回复
热议问题