如何将多边形等GDI对象绘制到内存数组中 [英] How do I draw GDI objects like polygon to an memory array

查看:162
本文介绍了如何将多边形等GDI对象绘制到内存数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用外部缓冲区来收集Sierpinski多边形的逐点生成。我想将多边形等GDI对象绘制到该缓冲区上。我正在为缓冲区成功生成内存设计上下文并在其上绘制多边形。我可以将它写入显示适配器并看到被多边形包围的Sierpinski点。当我生成一个.bmp文件时,我只看到了Sierpinski点。



我推断我的缓冲区本身并不受在内存设计上下文中绘制多边形的影响。它必须有自己的缓冲区。我想我正在将内存设备上下文缓冲区用于显示适配器。我正在使用自己的内存缓冲区来生成.bmp文件。



如果我可以将内存设备缓冲区的内容写入我自己的缓冲区,我想我可以解决我的问题。我怎样才能做到这一点? Pehaps我还可以将指向内存设备上下文缓冲区的指针传递给我的.bmp文件例程,如果我知道如何访问它。



I am using an external buffer to collect the dot-by-dot generation of Sierpinski polygons. I would like to draw GDI objects like polygons onto that buffer. I am successfully generating a memory devise context for the buffer and drawing a polygon on it. I can bitblt that to the display adapter and see Sierpinski dots surrounded with a polygon. When I generate a .bmp file I see only the Sierpinski dots.

I deduce my buffer per se is not affected by drawing the polygon on the memory devise context. It must have a buffer of its own. I guess I'm bitblting the memory device context buffer to the display adapter. I am using my own memory buffer to generate the.bmp file.

I think I can solve my problem if I can bitblt the contents of the memory device buffer to my own buffer. How can I do that? Pehaps I could also convey a pointer to the memory device contex buffer to my .bmp file routine, if I knew how to access that.

      hBitMap=CreateCompatibleBitmap(hdc,maxX,maxY);
   nBits=SetBitmapBits(hBitMap,maxW*maxY*4,ScreenBuffer); //  my buffer
hdcMem=CreateCompatibleDC(hdc);                        //  3rd buffer?
SelectObject(hdcMem,hBitMap);

BitBlt(hdc,0,0,xDisplay,yDisplay,hdcMem,0,0,SRCCOPY);

    if(fOutline)
{
  lBrush.lbStyle=BS_HOLLOW;
  hBrush=CreateBrushIndirect(&lBrush);
  SelectObject(hdcMem,hBrush);
  if(!Polygon(hdcMem,sPt, iCode+3))
      MessageBox(hWnd,"Bitmap polygon failed", "Sierpinski Polygons",0);
  BitBlt(hdc,0,0,xDisplay,yDisplay,hdcMem,0,0,SRCCOPY);

   }

 if(bBitMap)
{
   DibFileSave (szBitmapName,szAppName, maxX, maxY, ScreenBuffer);
 bBitMap=FALSE;
}
DeleteDC(hdcMem);

推荐答案

您必须更好地理解位图的概念。位图是存在图形像素的内存块。使用 CreateCompatibleBitmap ,您可以创建此类内存并获取(不透明)处理它。如果你需要这个位,你需要使用 GetDIBits



看看这个代码或我喜欢的文章 CXImage。
You must better understand the concept of Bitmaps. Bitmaps are memory chunks in which the graphic pixels exist. With CreateCompatibleBitmap you create such memory and get the (opaque) handle to it. If you want the bit you need to use GetDIBits.

Take a look on this code or my fav article CXImage.


这篇关于如何将多边形等GDI对象绘制到内存数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆