![]() Private Function GetControlBitmap(ByVal CTL As Control) As Bitmapĭim Methods() As = ( _ The following code returns a Bitmap of any control that draws via the OnPaint(.) I found an excellent solution for this problem here: What is VERY important is to remember to release the created objects: ToIn32 method in the BitBlt method - or you can declare the BitBlt with IntPtrs instead of Integers) Now you can use the new DC ( MemDC) to blit with (use the. ImageGraphics.DrawString(strText, Font, Brush, 1, 0) ' 1 pixelmargin to delete smudges ![]() ImageGraphics.Clear(Color.FromArgb(BackColor)) SelectObject(MemDC, HBitmap) ' selecting the Bitmap to the DCĭim ImageGraphics As Graphics = Graphics.FromHdc(MemDC) ' Creating a Graphics object to work with ![]() ObjSurfaceDC = objSurfaceGraphics.GetHdc() ' creating a DC for the target surfaceĭim MemDC As IntPtr = CreateCompatibleDC(objSurfaceDC) ' creating a new DC in memoryĭim HBitmap As IntPtr = TextImage.GetHbitmap TextImage = New Bitmap(CInt(objTextSize.Width + 2), CInt(ViewPort.Height)) ' +2 to delete smudges when moving the text So for us to be able to use BitBlt, we need 2 Device Contexts (hard to pronounce isn't it?) To create those, we first need a Graphics object, we create that one from ( almost) any object we want, for example, we can use a picture box: Creating a Device Context is Not That Complicated What are all the other parameters? There are the X, Y, Width, Height which tell BitBlt what is the area we wish to copy, and X and Y parameters to Where to copy at the target Device Context (which is used as our canvas). Now what we do is to copy Bitmaps from one location in the memory to another, these locations are called a Device Context, as they are directly connected to a Graphical Device on the system, for instance - a Picture Box or a Form. ( ByVal hdcDest As IntPtr, ByVal nXDest As Integer, _īyVal nYDest As Integer, ByVal nWidth As Integer, _īyVal nHeight As Integer, ByVal hdcSrc As IntPtr, _īyVal nXSrc As Integer, ByVal nYSrc As Integer, _ Private Declare Auto Function BitBlt Lib " GDI32.DLL" _ The function is located at the " GDI32.dll" library, and that's about it. Just to get things stated, in order to use the BitBlt function we have to declare it, as it is not a part of the Frameworks, but a part of the Window's API. In the demo project, I have created a class which copies to memory, and from memory using BitBlt, it's well documented and easy to understand. ![]() Plus - this sample code will provide a very clean and well commented class you can use to learn or even implement in your projects. What I will try to do here is to take it just one step further, give out some guidelines and pointers. (His article which is very informative and was the foundation for this article and code is located here.) So as very well introduced by Matthew Hazlett, the BitBlt comes to our aid by doing stuff VERY fast. When we want to use the graphics on a high frame rate, the DrawImage method just won't do, it's too slow (I am not sure why but it is :] ). NET environment offers us to Frameworks to do all kinds of cool stuff, including the Drawing classes and objects.
0 Comments
Leave a Reply. |