I am making a user control in vb.net. I am trying to use GDI, however, to handle the blitting, since GDI is faster.
I am using the hdcs that i retreive from graphics objects to pass to bitblt, and bitblt return values indicate a successful blit. But after I release the hdcs and try to display the bitmap on the screen, i get nothing but blackness.
It works, however with GDI+ functions.
Here is the GDI+ Version
Here is the GDI Version
Note that the only difference is that the GDI+ version uses drawimage() and the GDI version grabs the hdcs, uses bitblt(), then releases the hdcs, which would be the GDI equivalent, so I cant figure out why this wont work.
I am using the hdcs that i retreive from graphics objects to pass to bitblt, and bitblt return values indicate a successful blit. But after I release the hdcs and try to display the bitmap on the screen, i get nothing but blackness.
It works, however with GDI+ functions.
Here is the GDI+ Version
Code:
Dim Source As New Bitmap("D:\Visual studio projects\console\LEDWindows.bmp")
Dim GSource As Graphics = Graphics.FromImage(Source)
Dim hDCSource As IntPtr
Dim Persist As Bitmap
Dim GPersist As Graphics
Dim hDCPersist As IntPtr
Private Sub NewSize()
Dim i, j As Integer
Persist = New Bitmap(m_ConsoleSize.Width * 12, m_ConsoleSize.Height * 20)
GPersist = Graphics.FromImage(Persist)
For i = 0 To m_ConsoleSize.Width - 1
For j = 0 To m_ConsoleSize.Height - 1
GPersist.DrawImage(Source, i * CharWidth, j * CharHeight, New Rectangle(0, 40, 12, 20), GraphicsUnit.Pixel)
Next
Next
Me.BackgroundImage = Persist
Me.Refresh()
End Sub
Here is the GDI Version
Code:
Dim Source As New Bitmap("D:\Visual studio projects\console\LEDWindows.bmp")
Dim GSource As Graphics = Graphics.FromImage(Source)
Dim hDCSource As IntPtr
Dim Persist As Bitmap
Dim GPersist As Graphics
Dim hDCPersist As IntPtr
Private Sub NewSize()
Dim i, j As Integer
Persist = New Bitmap(m_ConsoleSize.Width * 12, m_ConsoleSize.Height * 20, Imaging.PixelFormat.Format24bppRgb)
GPersist = Graphics.FromImage(Persist)
hDCPersist = GPersist.GetHdc
hDCSource = GSource.GetHdc
For i = 0 To m_ConsoleSize.Width - 1
For j = 0 To m_ConsoleSize.Height - 1
BitBlt(hDCPersist, i * CharWidth, j * CharHeight, 12, 20, hDCSource, 0, 40, vbSrcCopy)
Next
Next
GPersist.ReleaseHdc(hDCPersist)
GSource.ReleaseHdc(hDCSource)
Me.BackgroundImage = Persist
Me.Refresh()
End Sub
Note that the only difference is that the GDI+ version uses drawimage() and the GDI version grabs the hdcs, uses bitblt(), then releases the hdcs, which would be the GDI equivalent, so I cant figure out why this wont work.