473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Bitmap.GetHIcon leaking GDI resources?

when I do this code
Dim HIcon As IntPtr = bmp.GetHicon to convert a Bitmap which is just a 16x16
image I pulled from a resource originally as an icon (16x16x32bit) then
converted into a bitmap to draw on it's surface then wanted to convert back
to an icon... but when I do the other two commands

Using bmp As Bitmap = My.Resources.bell.ToBitmap
Using g As Graphics = Graphics.FromImage(bmp)
end using
end using

GDI resources are released when they leave the using block. when I put the
HIcon IntPtr in there my GDI Object could is a never ending increment...
(this executes once a second to update the image, basically an animated
image when its used).. So this code causes a GDI leak

Using bmp As Bitmap = My.Resources.bell.ToBitmap
Using g As Graphics = Graphics.FromImage(bmp)
Dim HIcon As IntPtr = bmp.GetHicon
end using
end using

why? The only other code that is left after that leak is this

Using bmp As Bitmap = My.Resources.bell.ToBitmap
Using g As Graphics = Graphics.FromImage(bmp)
Dim HIcon As IntPtr = bmp.GetHicon
Using NewIcon As Icon = Icon.FromHandle(HIcon)

' Place onto drawing surface that requres an icon now...
end using
end using
end using
Oct 19 '07 #1
2 2878
"Smokey Grindel" <no****@nospam.comschrieb
when I do this code
Dim HIcon As IntPtr = bmp.GetHicon to convert a Bitmap which is just
a 16x16 image I pulled from a resource originally as an icon
(16x16x32bit) then converted into a bitmap to draw on it's surface
then wanted to convert back to an icon... but when I do the other
two commands

Using bmp As Bitmap = My.Resources.bell.ToBitmap
Using g As Graphics = Graphics.FromImage(bmp)
end using
end using

GDI resources are released when they leave the using block. when I
put the HIcon IntPtr in there my GDI Object could is a never ending
increment... (this executes once a second to update the image,
basically an animated image when its used).. So this code causes a
GDI leak
You have to call DestroyIcon (API function) to destroy the icon. Have a look
at the example in the help for GetHIcon method.
Armin

Oct 19 '07 #2
that would be exactly what I missed. thanks!

"Armin Zingler" <az*******@freenet.dewrote in message
news:uW**************@TK2MSFTNGP04.phx.gbl...
"Smokey Grindel" <no****@nospam.comschrieb
>when I do this code
Dim HIcon As IntPtr = bmp.GetHicon to convert a Bitmap which is just
a 16x16 image I pulled from a resource originally as an icon
(16x16x32bit) then converted into a bitmap to draw on it's surface
then wanted to convert back to an icon... but when I do the other
two commands

Using bmp As Bitmap = My.Resources.bell.ToBitmap
Using g As Graphics = Graphics.FromImage(bmp)
end using
end using

GDI resources are released when they leave the using block. when I
put the HIcon IntPtr in there my GDI Object could is a never ending
increment... (this executes once a second to update the image,
basically an animated image when its used).. So this code causes a
GDI leak

You have to call DestroyIcon (API function) to destroy the icon. Have a
look at the example in the help for GetHIcon method.
Armin

Oct 19 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Urs Vogel | last post by:
Hi I have an image list with icons and would like to change the form icon depending on an operating mode, but I couldn't figure out how to re-assign an image from the image list to the form.icon...
5
by: Dennis | last post by:
I give up...I have tried all combinations that I can think of and I can't get a bitmap converted to an icon and save it in a filestream or stream; Any help would be appreciated. -- Dennis in...
6
by: Dennis | last post by:
Can I create a cusor in vb.net code from a bitmap? -- Dennis in Houston
2
by: Dennis | last post by:
I have created a bitmap and set the transparency color to black; mybitmap.MakeTransparent(Color.Black) myicon = Icon.FromHandle(bm.GetHicon) This creates the icon ok but the background color...
3
by: Dennis | last post by:
I have a bitmap and make the color transparent; mybitmap.MakeTransparent(Color.Black) When I save it as a Icon, the black color is not transparent. However, if I save it as a bitmap then...
2
by: jaumef_2000 | last post by:
Hello, I'm developing a Standard Windows App and I need to deal with Icons. I've read lots of posts about them and I'm missing something. I put this code in a button click in a new brand new...
2
by: Robinson | last post by:
Hi, Can anyone point me towards a good drag/drop tutorial that allows me to create/render my own drag-cursor (i.e. for instance, if I wish to drag a list item, I can render the list item at the...
8
by: Frank | last post by:
Given a bitmap I want to write a Icon file using it. I believe I can do it except for writing the bits of the image. Can you tell me how to get the bits into a ByteArray Thanks
0
by: raylopez99 | last post by:
I have a minor problem locating an image file to load as a Bitmap. A resource file "NudeSusan.jpeg" (which I think is actually a bmp file, originally taken from a jpeg of model Susan Spears) is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.