Drawing Performance

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
 
S

Simon Hart [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top