I am having some trouble understanding why Graphics.ScaleTransform decreases so much the performance of the Graphics.FillRegion.
I am developing an application where I draw Regions in the PictureBox's paint event. This procedure works as expected, with a very good performance and without any kind of delay. The problem arises when I use the ScaleTransform method together with a custom Zooming tool.
So far my code looks like this:
protected void drawPicBox(object sender, PaintEventArgs e)
{
e.Graphics.SetClip(new Rectangle(picBox_x_padding,
picBox_y_padding,
(picBox_x_padding == 0.0) ? picBoxImage.Width : picBoxImage.Width - 2 * .picBox_x_padding,
(picBox_y_padding == 0.0) ? picBoxImage.Height : picBoxImage.Height - 2 * picBox_y_padding));
if (zoom_rate > 1.0)
{
e.Graphics.ScaleTransform(zoom_rate, zoom_rate);
}
e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
e.Graphics.CompositingQuality = CompositingQuality.HighSpeed;
e.Graphics.PixelOffsetMode = PixelOffsetMode.HighSpeed;
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
foreach (var item in regions)
{
// Paint the semantic group
e.Graphics.FillRegion(new SolidBrush(item.Color), item.Region);
}
}
While no zoom is set (zoom_rate == 1.0), the algorithm works reasonably well (~20ms) in terms of elapsed time, but as soon as the zoom_rate is over 1.0 and the graphics scaling is performed, the elapsed time starts to go up at a factor of approximately 30ms per 0.2 of zoom_rate increase.
For my application, this is not acceptable at all because after zooming too much the image displayed in the Picture box (Image size never superior to 1200px on each dimension), the elapsed time starts to go over 200ms, which makes the process really tedious to handle.
I do not know if I'm missing something, but I would appreciate any kind of suggestion in terms of how can I deal with this problem.
Thank you in advance!