-
BitBlt - Gdi objects
I’ve got a problem with Bitblt. When I use it to draw things the first time gdi objects are created and I can’t find out how to destroy them. I’m simply tiling a bitmap(using bitblt) onto a picturebox and then am putting the result into a picturebox which I want to store the image in. Since the processing must be invisible the pictures’ autoredraw properties are set to true. Here is the code that I am using:
Code:
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Sub Command1_Click()
picRender.Width = 400: picRender.Height = picTile.Height
For i = 0 To 400 Step picTile.Width
BitBlt picRender.hDC, i, 0, picTile.Width, picTile.Height, picTile.hDC, 0, 0, vbSrcCopy
Next i
picRender.Picture = picRender.Image
picDest.Picture = picRender.Picture
picRender.Picture = Nothing
End Sub
When I look at the amount of gdi objects in task manager I see that 3 are created during this process, would like to chop it down to 0.
Help will be much appreciated
-
Re: BitBlt - Gdi objects
Public Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As Long
ex:
DeleteDC tempDC
-
Re: BitBlt - Gdi objects
Thanks, I tried using DeleteDC and I got it to work without creating any new gdi objects being created. However when I set the pictureboxes' autoredraw property to true (the pictureboxes need to be invisible) a bunch of new gdi objects get created.
-
Re: BitBlt - Gdi objects
You will never chop the GDI objects down to zero. You must be able to get the count down to the count just before your project started. In my signature below is a "Memory Leak" tutorial you may find very useful
-
Re: BitBlt - Gdi objects
Thanks for the help, I'm not very familiar with gdi and wanted to check.
-
Re: BitBlt - Gdi objects
Definitely read the tutorial/FAQ I mentioned. You may very well be leaking GDI objects. It is very common to do so when refreshing a DC if you selected objects into that DC. The tutorial touches on that and much more.