• <small id='9M7D6'></small><noframes id='9M7D6'>

  • <i id='9M7D6'><tr id='9M7D6'><dt id='9M7D6'><q id='9M7D6'><span id='9M7D6'><b id='9M7D6'><form id='9M7D6'><ins id='9M7D6'></ins><ul id='9M7D6'></ul><sub id='9M7D6'></sub></form><legend id='9M7D6'></legend><bdo id='9M7D6'><pre id='9M7D6'><center id='9M7D6'></center></pre></bdo></b><th id='9M7D6'></th></span></q></dt></tr></i><div id='9M7D6'><tfoot id='9M7D6'></tfoot><dl id='9M7D6'><fieldset id='9M7D6'></fieldset></dl></div>
    1. <legend id='9M7D6'><style id='9M7D6'><dir id='9M7D6'><q id='9M7D6'></q></dir></style></legend>

        <bdo id='9M7D6'></bdo><ul id='9M7D6'></ul>

      <tfoot id='9M7D6'></tfoot>

        Win32 C/C++ 从内存缓冲区加载图像

        时间:2023-08-01

            <tbody id='rFIMM'></tbody>
        1. <tfoot id='rFIMM'></tfoot>

            <small id='rFIMM'></small><noframes id='rFIMM'>

            <i id='rFIMM'><tr id='rFIMM'><dt id='rFIMM'><q id='rFIMM'><span id='rFIMM'><b id='rFIMM'><form id='rFIMM'><ins id='rFIMM'></ins><ul id='rFIMM'></ul><sub id='rFIMM'></sub></form><legend id='rFIMM'></legend><bdo id='rFIMM'><pre id='rFIMM'><center id='rFIMM'></center></pre></bdo></b><th id='rFIMM'></th></span></q></dt></tr></i><div id='rFIMM'><tfoot id='rFIMM'></tfoot><dl id='rFIMM'><fieldset id='rFIMM'></fieldset></dl></div>

              <bdo id='rFIMM'></bdo><ul id='rFIMM'></ul>

                <legend id='rFIMM'><style id='rFIMM'><dir id='rFIMM'><q id='rFIMM'></q></dir></style></legend>
                  本文介绍了Win32 C/C++ 从内存缓冲区加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想在 Win32 应用程序上加载图像 (.bmp) 文件,但我不想使用 Windows API 中的标准 LoadBitmap/LoadImage:我希望它从内存中已有的缓冲区加载.我可以轻松地直接从文件加载位图并将其打印在屏幕上,但这个问题让我卡住了.

                  I want to load an image (.bmp) file on a Win32 application, but I do not want to use the standard LoadBitmap/LoadImage from Windows API: I want it to load from a buffer that is already in memory. I can easily load a bitmap directly from a file and print it on the screen, but this issue is making me stuck.

                  我正在寻找的是一个像这样工作的函数:

                  What I'm looking for is a function that works like this:

                  HBITMAP LoadBitmapFromBuffer(char* buffer, int width, int height);
                  

                  推荐答案

                  没关系,我找到了我的解决方案!这是初始化代码:

                  Nevermind, I found my solution! Here's the initializing code:

                  std::ifstream is;
                  is.open("Image.bmp", std::ios::binary);
                  is.seekg (0, std::ios::end);
                  length = is.tellg();
                  is.seekg (0, std::ios::beg);
                  pBuffer = new char [length];
                  is.read (pBuffer,length);
                  is.close();
                  
                  tagBITMAPFILEHEADER bfh = *(tagBITMAPFILEHEADER*)pBuffer;
                  tagBITMAPINFOHEADER bih = *(tagBITMAPINFOHEADER*)(pBuffer+sizeof(tagBITMAPFILEHEADER));
                  RGBQUAD             rgb = *(RGBQUAD*)(pBuffer+sizeof(tagBITMAPFILEHEADER)+sizeof(tagBITMAPINFOHEADER));
                  
                  BITMAPINFO bi;
                  bi.bmiColors[0] = rgb;
                  bi.bmiHeader = bih;
                  
                  char* pPixels = (pBuffer+bfh.bfOffBits);
                  
                  char* ppvBits;
                  
                  hBitmap = CreateDIBSection(NULL, &bi, DIB_RGB_COLORS, (void**) &ppvBits, NULL, 0);
                  SetDIBits(NULL, hBitmap, 0, bih.biHeight, pPixels, &bi, DIB_RGB_COLORS);
                  
                  GetObject(hBitmap, sizeof(BITMAP), &cBitmap);
                  

                  这篇关于Win32 C/C++ 从内存缓冲区加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:C++ Win32 键盘事件 下一篇:为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码

                  相关文章

                  最新文章

                    <small id='BJXOc'></small><noframes id='BJXOc'>

                    <tfoot id='BJXOc'></tfoot>

                  1. <i id='BJXOc'><tr id='BJXOc'><dt id='BJXOc'><q id='BJXOc'><span id='BJXOc'><b id='BJXOc'><form id='BJXOc'><ins id='BJXOc'></ins><ul id='BJXOc'></ul><sub id='BJXOc'></sub></form><legend id='BJXOc'></legend><bdo id='BJXOc'><pre id='BJXOc'><center id='BJXOc'></center></pre></bdo></b><th id='BJXOc'></th></span></q></dt></tr></i><div id='BJXOc'><tfoot id='BJXOc'></tfoot><dl id='BJXOc'><fieldset id='BJXOc'></fieldset></dl></div>
                  2. <legend id='BJXOc'><style id='BJXOc'><dir id='BJXOc'><q id='BJXOc'></q></dir></style></legend>
                      <bdo id='BJXOc'></bdo><ul id='BJXOc'></ul>