Hey, I've been trying to make a game using pure VB, and obviously one must use many graphics objects. This is just test code, but still, when I debug the program, the memory still goes up to 600-700MB. Graphics objects are created and used very fast as you can see. How can I reduce this? Do I need to dispose of them after being used?
Thanks!
~Nic
vb Code:
Public Class Form1 Dim DefaultImg As New Bitmap(My.Resources.TestImg) Dim T1 As New Timer() With {.Interval = 10, .Enabled = True} Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load DoubleBuffered = True AddHandler T1.Tick, AddressOf T1_Tick End Sub Private Function LotOfCode() As Bitmap Dim Bmp As New Bitmap(800, 600) Dim G As Graphics = Graphics.FromImage(Bmp) G.DrawImage(DefaultImg, -5, -5) G.FillRectangle(Brushes.Red, 5, 5, 15, 15) Return Bmp End Function Private Sub T1_Tick() Invalidate() End Sub Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor Dim TestImg As Bitmap = LotOfCode() Dim ImgPt As New Point(25, 25) e.Graphics.DrawImage(TestImg, ImgPt) End Sub End Class




Reply With Quote
