Ver Mensaje Individual
  #2 (permalink)  
Antiguo 02/02/2012, 17:25
alexg88
 
Fecha de Ingreso: abril-2011
Mensajes: 1.342
Antigüedad: 13 años, 9 meses
Puntos: 344
Respuesta: Timer "acaparaRAM"

Creo que el problema es que no liberas los recursos del objeto graphics ni del objeto Bitmap. La forma de hacer esto es llamar al método Dispose al terminar con ellos o usar using.

Con Using:

Código VB:
Ver original
  1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  2.         If IsWindowVisible(GetForegroundWindow()) And statuswindow = False Then
  3.             Dim rct As RECT
  4.             Dim victima As Long = GetForegroundWindow()
  5.             GetWindowRect(GetForegroundWindow(), rct)
  6.  
  7.            Using bmpScreenshot As New Bitmap(rct.Right - rct.Left, rct.Bottom - rct.Top, PixelFormat.Format24bppRgb)
  8. Using gfxScreenshot As Graphics.FromImage(bmpScreenshot)
  9.             gfxScreenshot.CopyFromScreen(rct.Left, rct.Top, 0, 0, New Size(rct.Right - rct.Left, rct.Bottom - rct.Top), CopyPixelOperation.SourceCopy)
  10.  
  11.  
  12.             Try
  13.                 bmpScreenshot.Save(sTempFolderPath & victima & ".png")
  14.             Catch ex As Exception
  15.  
  16.             End Try
  17.  
  18.            End Using
  19. End Using
  20.         End If
  21.  
  22.     End Sub


Sin Using:

Código VB:
Ver original
  1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  2.         If IsWindowVisible(GetForegroundWindow()) And statuswindow = False Then
  3.             Dim rct As RECT
  4.             Dim victima As Long = GetForegroundWindow()
  5.             GetWindowRect(GetForegroundWindow(), rct)
  6.  
  7.             Dim bmpScreenshot As Bitmap = New Bitmap(rct.Right - rct.Left, rct.Bottom - rct.Top, PixelFormat.Format24bppRgb)
  8.             Dim gfxScreenshot As Graphics = Graphics.FromImage(bmpScreenshot)
  9.             gfxScreenshot.CopyFromScreen(rct.Left, rct.Top, 0, 0, New Size(rct.Right - rct.Left, rct.Bottom - rct.Top), CopyPixelOperation.SourceCopy)
  10.  
  11.  
  12.             Try
  13.                 bmpScreenshot.Save(sTempFolderPath & victima & ".png")
  14.             Catch ex As Exception
  15.  
  16.             End Try
  17.  
  18.             gfxScreenshot.Dispose();
  19. bmpScreenshot.Dispose();
  20.  
  21.  
  22.         End If
  23.  
  24.     End Sub