Drawing Performance

  • Thread starter Thread starter werD
  • Start date Start date
W

werD

Would it be more performant to instantiate and destroy the objects below
closer to their use or is it always best practice to precache drawing objects
before doing the drawing.

basic example

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
Dim buffed_Graphx As Graphics = Graphics.FromImage(m_BackGround)
Dim brushBG As SolidBrush = New SolidBrush(Color.Brown)
Dim bmpBG As Bitmap = SmartDeviceProject1.My.Resources.Drew
Dim at As New ImageAttributes
at.SetColorKey(Color.Pink, Color.Pink)

Dim dstRect As New Rectangle(0, 0, _
m_ScreenWidth, m_ScreenHeight)
Dim dstRect2 As New Rectangle(0, 0, _
m_BackGround.Width, m_BackGround.Height)
If CtrlsLoaded = False Then
buffed_Graphx.FillRectangle(brushBG, 0, 0, _
m_ScreenWidth, m_ScreenHeight)
End If


buffed_Graphx.DrawImage(bmpBG, dstRect, 0, 0, bmpBG.Width,
bmpBG.Height, _
GraphicsUnit.Pixel, at)
buffed_Graphx.Dispose()
e.Graphics.DrawImage(m_BackGround, dstRect2, 0, 0, _
m_BackGround.Width, m_BackGround.Height,
GraphicsUnit.Pixel, at)
at.Dispose()
brushBG.Dispose()
If CtrlsLoaded = False Then
AddControls()
End If
End Sub
 
It won't make a lot of difference. Caching images do make a difference
however - depending on the size. My advice, as always with perf tips is to
change then measure.
 
Back
Top