【问题标题】:How to save 1 BPP, 4 BPP and 8BPP image如何保存 1 BPP、4 BPP 和 8BPP 图像
【发布时间】:2011-09-20 09:16:17
【问题描述】:

谁能告诉我如何将 1BPP、4BPP 和 8BPP 保存为位图。我在图像、宽度和高度中有位。

请告诉我如何将其保存为位图。

【问题讨论】:

    标签: c++ windows winapi visual-c++


    【解决方案1】:

    对于 Windows 和 C++,最简单的方法是 Gdiplus。这是一些伪代码。

    Gdiplus::Bitmap* pBmp = new Gdiplus::Bitmap(width, height, pixelformat);
    pBmp->SetPalette(...); // initialize palette for 8bpp formats and less
    pBmp->LockBits(...); // acquire the bitmap buffer
    
    // copy your binary image data into the buffer
    
    pBmp->UnlockBits(...); // return the buffer
    
    pBmp->Save(filename, &clsidBMP, NULL);
    
    delete pBmp;
    

    您可以获取由 GDI 加上here 定义的像素格式列表。

    您需要的大部分内容由 Bitmap 类定义,该类继承自 Image 类,后者定义了 Save 方法。

    “保存”方法所需的编码器 clsid 有点难以获得。但是请参阅我的帖子here,了解如何获取此值。

    【讨论】:

      【解决方案2】:
      ATL::CImage* image_ = new CImage();
      image_ -> Create( rect.right - rect.left, rect.bottom - rect.top, 32 );
      
      ...
      image_ -> Save( filename );
      delete image_;
      

      适当更改 Create() 中的参数。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-07-11
        • 2011-01-31
        • 2023-03-23
        • 1970-01-01
        • 1970-01-01
        • 2013-03-25
        • 1970-01-01
        • 2016-06-22
        相关资源
        最近更新 更多