<small id='4RdOb'></small><noframes id='4RdOb'>

    <tfoot id='4RdOb'></tfoot>

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

      绘制 8bpp 灰度位图(非托管 C++)

      Drawing on 8bpp grayscale bitmap (unmanaged C++)(绘制 8bpp 灰度位图(非托管 C++))

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

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

          • <legend id='SYX97'><style id='SYX97'><dir id='SYX97'><q id='SYX97'></q></dir></style></legend>

              <tbody id='SYX97'></tbody>

              • <bdo id='SYX97'></bdo><ul id='SYX97'></ul>
                本文介绍了绘制 8bpp 灰度位图(非托管 C++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我一直试图在 8bpp 灰度位图上绘制但没有成功.这是我的一些尝试.也许有人可以指出我做错了什么.

                I've been attempting to draw on an 8bpp grayscale bitmap without success. Here are some of my attempts. Maybe someone can point out what I'm doing wrong.

                ==================================================

                ===================================================

                尝试 1:创建、选择和绘制:

                Attempt 1: Create, select, and draw:

                在构造函数中:

                CBitmap bm;
                bm.CreateBitmap (200, 200, 1, 8, NULL);
                

                在 OnDraw 中:

                In OnDraw:

                CDC *mdc=new CDC ();
                HGDIOBJ tmp = mdc->SelectObject(bm);
                

                结果:tmp 为NULL,表示失败.

                Result: tmp is NULL, indicating failure.

                ==================================================

                ===================================================

                尝试 2:创建DIBSection

                Attempt 2: CreateDIBSection

                在构造函数中:

                HBITMAP hbm;
                BITMAPINFOHEADER bih;
                BITMAPINFO bi;
                HANDLE hb;
                CDC* myDc = new CDC ();
                HDC hdc = myDc->GetSafeHdc ();
                void* bits;
                RGBQUAD rq [256];
                
                 initBi ();
                 hbm = CreateDIBSection (hdc, &bi, DIB_RGB_COLORS, &bits, NULL, 0);
                
                ...
                
                void CEightBitDrawingView::initBi()
                {
                 bih.biSize = sizeof (BITMAPINFOHEADER);
                 bih.biWidth = 200;
                 bih.biHeight = -200;
                 bih.biPlanes = 1;
                 bih.biBitCount = 8;
                 bih.biCompression = BI_RGB;
                 bih.biSizeImage = 0;
                 bih.biXPelsPerMeter = 14173;
                 bih.biYPelsPerMeter = 14173;
                 bih.biClrUsed = 0;
                 bih.biClrImportant = 0;
                
                 memset ((void *) rq, 0, 256 * sizeof (RGBQUAD));
                
                 bi.bmiHeader = bih;
                 bi.bmiColors = rq;
                }
                

                结果:这甚至无法编译,因为 BITMAPIINFO bmiColors 成员定义为:RGBQUAD bmiColors[1];

                Result: This doesn't even compile because the BITMAPINFO bmiColors member is defined as: RGBQUAD bmiColors[1];

                所以不会接受超过一种 RGB 颜色.事实上,我分配给该成员的任何内容都无法编译!(他们能不能让它变得更复杂!?)

                so won't accept more than one RGB color. In fact, nothing I assign to this member compiles! (Could they possibly make it any more complex!?)

                任何建议将不胜感激!谢谢!

                Any suggestions would be appreciated! Thanks!

                ==================================================

                ===================================================

                推荐答案

                这里.演示如何 - 在非托管环境中 - 在堆栈上分配动态大小的结构、填充它并将其传递给 CreateDIBSection 的代码.

                Here. Code that demonstrates how to - in a not managed world - allocate a dynamically sized structure on the stack, fill it in and pass it to CreateDIBSection.

                #include <malloc.h>
                
                HBITMAP CreateGreyscaleBitmap(int cx, int cy)
                {
                  BITMAPINFO* pbmi = (BITMAPINFO*)alloca( sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*256);
                  pbmi->bmiHeader.biSize = sizeof (pbmi->bmiHeader);
                  pbmi->bmiHeader.biWidth = cx;
                  pbmi->bmiHeader.biHeight = cy;
                  pbmi->bmiHeader.biPlanes = 1;
                  pbmi->bmiHeader.biBitCount = 8;
                  pbmi->bmiHeader.biCompression = BI_RGB;
                  pbmi->bmiHeader.biSizeImage = 0;
                  pbmi->bmiHeader.biXPelsPerMeter = 14173;
                  pbmi->bmiHeader.biYPelsPerMeter = 14173;
                  pbmi->bmiHeader.biClrUsed = 0;
                  pbmi->bmiHeader.biClrImportant = 0;
                
                  for(int i=0; i<256; i++)
                  {
                    pbmi->bmiColors[i].rgbRed = i;
                    pbmi->bmiColors[i].rgbGreen = i;
                    pbmi->bmiColors[i].rgbBlue = i;
                    pbmi->bmiColors[i].rgbReserved = 0;
                  }
                
                  PVOID pv;
                  return CreateDIBSection(NULL,pbmi,DIB_RGB_COLORS,&pv,NULL,0);
                }
                

                这篇关于绘制 8bpp 灰度位图(非托管 C++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                C++ stl unordered_map implementation, reference validity(C++ stl unordered_map 实现,参考有效性)
                C++: Is it possible to use a reference as the value in a map?(C++:是否可以使用引用作为映射中的值?)
                Where ampersand quot;amp;quot; can be put when passing argument by reference?(其中符号“amp;通过引用传递参数时可以放置吗?)
                Why can a non-const reference parameter be bound to a temporary object?(为什么可以将非常量引用参数绑定到临时对象?)
                What is a dangling reference?(什么是悬空引用?)
                C++ reference changes when push_back new element to std::vector(当 push_back 新元素到 std::vector 时,C++ 引用发生变化)

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

                <tfoot id='t36sU'></tfoot>

                  <tbody id='t36sU'></tbody>

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