|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionAs most of you already know, the .NET environment offers us to Frameworks to do all kinds of cool stuff, including the Drawing classes and objects. BUT? When we want to use the graphics on a high frame rate, the What I will try to do here is to take it just one step further, give out some guidelines and pointers. Plus - this sample code will provide a very clean and well commented class you can use to learn or even implement in your projects. In the Demo Project i have created a Class which Copies to memory, and from memory using
A Quick Run Through The BasicsJust to get things stated, in order to use the Private Declare Auto Function BitBlt Lib "GDI32.DLL" _
( ByVal hdcDest As IntPtr, ByVal nXDest As Integer, _
ByVal nYDest As Integer, ByVal nWidth As Integer, _
ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, _
ByVal nXSrc As Integer, ByVal nYSrc As Integer, _
ByVal dwRop As Int32) As Boolean
Now what we do is to copy Bitmaps from one location in the memory to another, these location 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. What are all the other parameters? there are the X,Y,Width,Height which tells
Creating a Device Context is not that complicatedSo for us to be able to use PictureBox1.CreateGraphics
' But we need to keep a refference to it so we will use this:
Dim GrpObj as Graphics = PictureBox1.CreateGraphics
Now we have Dim MyDeviceContext as IntPtr ' Creating the
' variable to keep the DC address
MyDeviceContext = GrpObj.GetHdc()
(Note: Hdc = Handle of Device Context) Now what did we just do? we created an Object in Memory which represents the Graphical Object
Now we need another Device Context to copy to, to do so we will create an invisible Device Context in the memory very easily. ' We Create a Bitmap object at the desired size,
Dim srcBmp As New Bitmap(Size.Width, Size.Height, GrpObj)
' Creating Graphics Objects
MemoryGrpObj = Graphics.FromImage(srcBmp) 'Create a Graphics object
' Creating a Device Context
MemoryHdc = MemoryGrpObj.GetHdc 'Get the Device Context
BitBliting the imagesNow we can copy anything we want to or from this Device Context. Providing
Now we can Actualy Blit:BitBlt(MemoryHDC, 0, 0, width, Height, MyDeviceContext, 0, 0, SRCCOPY) ^ Target ^ ^ Source ^
This will copy From
All we need to do now is to create our target Device Context, and To finish up, note that if you want to Draw on a specific location here is the syntax: BitBlt(TargetHdc, Xpos, Ypos, width, Height, MemoryHDC, 0, 0, SRCCOPY)
^ ^
'(Assuming the TargetHdc is our target Device Context,
'and Xpos and Ypos are the location to draw at)
The Sample Project will demonstrate it all and maybe save you the trouble. Good Luck.
|
||||||||||||||||||||||