Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
hey, this kinda falls under interop too, but I wanted to know if GDI (BitBlt) would be faster than .NETs GDI+. I found a way to use old GDI with C++ .DLLs so would it be faster under C++?
  • *Experts*
Posted

You dont need to create any C++ DLL to use GDI32 in your .NET app. You can simply declare the function and use it.

As far as comparison goes. A lot of people will say that GDI32 is faster than GDI+. But using GDI+ from .NET is MUCH easier.

Posted

Yes, GDI is much faster.

 

I made a class library a while back to make GDI easier to use. Feel free to expand on it to meet your own needs. If you want to see a sample of it being used, do a search for Sharp Invader. It's a game I made using this GDI library.

gdi.zip

Gamer extraordinaire. Programmer wannabe.
Posted

I don't have C#, I have VB and C++.

 

btw, for using bitblt, do I just use GetWindowsDC(Me.Handle) or something like that?

Posted

ok, I tried the following but it gave me:

An unhandled exception of type 'System.InvalidOperationException' occurred in system.windows.forms.dll

 

Additional information: The object is currently in use elsewhere.

 

here's the code:

   Public Sub Blt(ByVal img As Image, ByVal e As Graphics, ByVal rct As Rectangle)
       Dim graph As Graphics = Graphics.FromImage(img)
       Dim imgHDC As Long = graph.GetHdc.ToInt64
       Dim hdc As Long = e.GetHdc.ToInt64
       Dim retval As Long

       retval = BitBlt(hdc, CRD_AREA.X, CRD_AREA.Y, CRD_AREA.Width, CRD_AREA.Height, imgHDC, 0, 0, &HCC0020)

       graph.Dispose()
   End Sub

Posted

BitBlt uses Int32 not Int64 (Integer not Long)

Public Sub Blt(ByVal img As Image, ByVal e As Graphics, ByVal rct As Rectangle)
       Dim graph As Graphics = Graphics.FromImage(img)
       Dim imgHDC As Integer = graph.GetHdc.ToInt32
       Dim hdc As Integer = e.GetHdc.ToInt32
       Dim retval As Integer

       retval = BitBlt(hdc, CRD_AREA.X, CRD_AREA.Y, CRD_AREA.Width, CRD_AREA.Height, imgHDC, 0, 0, &HCC0020)

       graph.ReleaseDC(imgHDC)
       graph.Dispose()

       e.ReleaseDC(hdc)
   End Sub

GDI+ has more features then GDI, If you use GDI+ effeciently the slower speed will make minimal difference

.Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
Posted (edited)

I'm just using it in a couple places for boosts of speed (simple square images)

 

just a question, how can I convert the integer's to IntPtr, ReleaseHDC doesn't have an overload for Integer

Edited by Darc
Posted

I recommend using this BitBlt declaration:

Declare Function BitBlt Lib "gdi32.dll" (ByVal hDestDC As IntPtr, ByVal x As Int32, _
ByVal y As Int32, ByVal nWidth As Int32, ByVal nHeight As Int32, ByVal hSrcDC As IntPtr, _
 ByVal xSrc As Int32, ByVal ySrc As Int32, ByVal dwRop As Int32) As Int32

The Bitblt function can now use IntPtr objects, it works fine.

 

Or if you don't want to do that you can just alter the function:

    Public Sub Blt(ByVal img As Image, ByVal e As Graphics, ByVal rct As Rectangle)
       Dim graph As Graphics = Graphics.FromImage(img)
       Dim imgHDC As IntPtr = graph.GetHdc
       Dim hdc As IntPtr = e.GetHdc
       Dim retval As Integer

       retval = BitBlt(hdc.ToInt32, CRD_AREA.X, CRD_AREA.Y, CRD_AREA.Width, CRD_AREA.Height, imgHDC.ToInt32, 0, 0, &HCC0020)

       graph.ReleaseDC(imgHDC)
       graph.Dispose()

       e.ReleaseDC(hdc)
   End Sub

.Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...