Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C++
      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);
Posted
Updated 2-Mar-15 7:19am
v2
Comments
Sergey Alexandrovich Kryukov 2-Mar-15 13:47pm    
Just a note: Sierpinski polygon pattern is too simple to preserve it in memory. It could be better to render it directly on screen. For less regular fractals, it's really useful to preserve any number of images. From your code, I cannot understand where is the source of your image bits, and what's the problem. Where did you originally rendered the image?
And why not do the opposite: first render the image in memory and then render it on scree?
—SA
Sir Roland 2-Mar-15 21:07pm    
Sorry SA, I did some more digging and came up with a solution myself. But when I reread your answer after I composed a note bragging about my success, I saw that my solution was in function exactly what you recommended. We just used device dependent functions How do I take back my rejection of your solution?

1 solution

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.
 
Share this answer
 
Comments
Sir Roland 2-Mar-15 17:07pm    
Thanks for your input. Apparently I don't have the ability to communicate I though I have. You are not answering the question, so perhaps I didn't state it well. This is being done as part of some academic work.

I am calculating millions of points to get an image of about 60,000 pixels. The calculations obviously results in thousands of duplicates. Printing 32-bit pixels to the screen is extremely slow. As I understand it, the display adapter takes the time to match every pixel to those in its repertoire to make sure it is using the best choice. Everyone I know who studies fractals seriously writes the data to an external file and transfers the result to the screen to avoid this time delay. With this workaround I can plot over a couple of billion points in less than two minutes. If I wrote directly to the screen, this would take hours.

The end point of the work is not a bit map. This is a way of explaining what I need. I am trying to advance understand of the random dot process by which millions of randomly generated dots results in images of such order and beauty as manifest in Sierpinski polygons. I have in mind several avenues of exploration that will be facilitated if I can draw polygons on my screen buffer before I begin the iteration process. If you have expertise, please help me out here. I am hoping for simple answers to what I think is simple problem.

Regards, Sir Roland.
KarstenK 3-Mar-15 2:25am    
Screen output is slow. If that is your key problem you only want the data in the memory you can use a bitmap in a MemoryDC. It wont get drawn on the screen so it runs faster. With a BiBlt you can print the pixels to screen.

If you really want performance, than think about accessing such bitmap bits via pointers. (Not the slow Get/SetPixel-API).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900