I did some profiling on my project and traced a paint function to using 80% of my project's processing time. Since it's so significant I feel like any improvements I do would greatly impact my performance. This function takes roughly 25 ms to finish which is about 40 fps and I hope to get it up to 60.
private void pic2OnPaint(object sender, PaintEventArgs e)
{
try
{
Rectangle rect = Rect();
e.Graphics.DrawImage(LatestScreenshot, new Point(-rect.Location.X, -rect.Location.Y));
if (PaintLayers.Count > 0 | ChosenTool != Option.None) // So it does not attempt to draw a blank bitmap.
{
e.Graphics.DrawImage(PaintSurface, new Point(-rect.Location.X, -rect.Location.Y));
}
if (!Holding & !PanelDragHolding & !HandleDragHolding) // So it does not attempt to draw a blank bitmap.
{
e.Graphics.DrawImage(invisibleLayer, new Point(-rect.Location.X, -rect.Location.Y));
}
}
catch { }
}
I would greatly appreciate any tips.
This gets called every frame. LatestScreenshot bitmap does not change. Paintsurface gets changed each frame. I put it in a try catch just because the only time it errors is once I initialize the project so LatestScreenshot is null for the first time it gets called. I do not get any errors other than that one.