Jump to content
Xtreme .Net Talk

Cynewulf

Members
  • Posts

    5
  • Joined

  • Last visited

Everything posted by Cynewulf

  1. Here's the modified code with the objects declared locally. The leak is still present... Dim ang As Integer = 0 Dim s As Integer = 4 Dim a As Double = 0 Private Sub timerTick_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerTick.Tick DoNotificationIcon(NF1) a = a + 0.15 ang += 8 + Int(14 * Math.Sin(a)) If ang > 180 Then ang -= 180 If ang < 0 Then ang += 180 End Sub Private Sub DoNotificationIcon(ByVal nf As NotifyIcon) Dim b As Bitmap Dim g As Graphics Dim r As Rectangle b = New Bitmap(16, 16) g = Graphics.FromImage(b) r = New Rectangle(0 - s, 0 - s, b.Width - 1 + (s * 2), b.Height - 1 + (s * 2)) g.FillPie(New SolidBrush(Color.Black), r, 0 + ang, 90) g.FillPie(New SolidBrush(Color.Black), r, -180 + ang, 90) g.FillPie(New SolidBrush(Color.White), r, 90 + ang, 90) g.FillPie(New SolidBrush(Color.White), r, -90 + ang, 90) nf.Icon = Icon.FromHandle(b.GetHicon) g.Dispose() b.Dispose() End Sub I guess the line I need a replacement for is 'nf.Icon = icn.FromHandle(b.GetHicon)'. I need a variant where it sets a pointer instead of creating a new instance of the icon. Bit stumped really :/ *EDIT* Slight mod to code to remove unnecessary 'icn' object
  2. I originally had all of my objects declared locally but I think the leak was even worse. Well it wasn't designed for real use. It's just a conceptual test :) It works because Icon.FromHandle(b.GetHicon) creates a copy of the icon rather than just setting a pointer. Which I think is the problem actually :/
  3. Well you can still use BitBlt in .NET with the correct declaration. I believe using BitBlt is faster than the GDI+ DrawImageUnscaled. Just depends on whether you plan to do anything fancy I suppose :D Article here on how to do it... http://www.codeproject.com/vb/net/BitBlt.asp
  4. Don't know if this will help but the way I used to do that in VB6 was to have the 'sprites' arrayed out on a single large bitmap. You can then blit from the appropriate point on your bitmap to your target destination. I'm sure you could apply the same thing to GDI+.
  5. I've written some code which creates a bitmap, draws on the bitmap using GDI+ and copies it to a notification icon control (NF1). It updates this bitmap (to draw a rotating swirly thing) in a timer loop (every 25ms). Problem is, I seem to be losing GDI objects. As far as I can tell the only place where this could be happening is in 'icn = Icon.FromHandle(b.GetHicon)'. Anyone any ideas how I can prevent this from happening? (Note : The application loses about 3-4Kb per second) Dim ang As Integer = 0 Dim s As Integer = 4 Dim a As Double = 0 Dim bbrsh As SolidBrush Dim wbrsh As SolidBrush Dim b As Bitmap Dim g As Graphics Dim r As Rectangle Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load bbrsh = New SolidBrush(Color.Black) wbrsh = New SolidBrush(Color.White) b = New Bitmap(16, 16) g = Graphics.FromImage(b) r = New Rectangle(0 - s, 0 - s, b.Width - 1 + (s * 2), b.Height - 1 + (s * 2)) Me.Visible = False End Sub Private Sub timerTick_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerTick.Tick DoNotificationIcon(NF1) a = a + 0.15 ang += 8 + Int(14 * Math.Sin(a)) If ang > 180 Then ang -= 180 If ang < 0 Then ang += 180 End Sub Private Sub DoNotificationIcon(ByVal nf As NotifyIcon) Dim icn As Icon g.FillPie(bbrsh, r, 0 + ang, 90) g.FillPie(bbrsh, r, -180 + ang, 90) g.FillPie(wbrsh, r, 90 + ang, 90) g.FillPie(wbrsh, r, -90 + ang, 90) icn = Icon.FromHandle(b.GetHicon) nf.Icon = icn icn.Dispose() End Sub !EDIT! : I've narrowed it down to the line "icn = Icon.FromHandle(b.GetHicon)". It creates a new icon each time around. I'm just not sure how to prevent this from happening. Anyone?
×
×
  • Create New...