C# and BitBlt
-
I used BitBlt in a c# program when I set the Form as the Source a Bitmap as the destination It works but when I set Form as th destination whatever the bitmap is It just show as black why?
I remember when I did some drawing, it came out black if the bitmaps were of incompatible format. (Maybe the form is 256 colours and bitmap is 32bit? Then 256 colours -> 32bit conversion is easy, but 32bit -> 256 is not. I'm not sure if it converts like that, but it's possible)
-
I used BitBlt in a c# program when I set the Form as the Source a Bitmap as the destination It works but when I set Form as th destination whatever the bitmap is It just show as black why?
The reason for this is stated in this Knowledge Base article[^]. Using GDI on a GDI+ Graphics Object Backed by a Bitmap When Graphics::GetHDC() is called for a Graphics object that is backed by a bitmap rather than the screen, a memory HDC is created and a new HBITMAP is created and selected into the memory HDC. This new memory bitmap is not initialized with the original bitmap's image but rather with a sentinel pattern, which allows GDI+ to track changes to the bitmap. Any changes that are made to the memory bitmap through the use of GDI code become apparent in changes to the sentinel pattern. When Graphics::ReleaseHDC() is called, those changes are copied back to the original bitmap. Because the memory bitmap is not initialized with the bitmap's image, an HDC that is obtained in this way should be considered "write only" and is therefore not suitable for use with ROPs, the use of which requires the ability to read the target, like R2_XOR. Also, there is a performance cost to this approach because GDI+ must copy the changes back to the original bitmap.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi