0

I've created a graph(Diagram) on PictureBox control. This control has the ability to zoom/pen. When I want to zoom, it slows down.

Thanks for helping someone

    public void Render(bool resizeToo = false)
    {

        if (resizeToo)
        {
            plt.settings.Resize(pb.Width, pb.Height);
            if (plt2 != null)
            {
                plt2.settings.Resize(plt.settings.width, plt.settings.height);
            }
        }

        if (plt2 == null)
        {
            pb.Image = plt.figure.GetBitmap();
        }
        else
        {
            // if plt2 contains a GraphControl, match its X axis to the user control then overlay it
            plt2.settings.axisX.Set(plt.settings.axisX.x1, plt.settings.axisX.x2);
            Bitmap bmp1 = plt.figure.GetBitmap();
            Bitmap bmp2 = plt2.figure.GetBitmap();
            Bitmap bmpMerged = new Bitmap(bmp1);
            using (Graphics gfx = Graphics.FromImage(bmpMerged))
                gfx.DrawImage(bmp2, new Rectangle(0, 0, bmp2.Width, bmp2.Height));
            pb.Image = bmpMerged;
        }
        Application.DoEvents();

    }

enter image description here

Leonardo Alves Machado
  • 2,747
  • 10
  • 38
  • 53
Hakels
  • 1
  • PictureBox does nothing to make rendering the Image fast, it is optimized to minimize memory usage instead of rendering speed. That mattered 17 years ago. You have to help, start by making the new image exactly as large as the PictureBox.ClientSize so it doesn't have to be resized when it is drawn. Next opportunity is the pixel format you choose for the new image, 32bppPArgb is ten times faster than any other format since it doesn't have to be converted to the video adapter format. – Hans Passant May 20 '19 at 14:00
  • I see no resizing code. Is the speed ok without resizing..? - Also: Are you leaking bmp1 and bmp2..? – TaW May 20 '19 at 14:40
  • What is your suggestion for doing this? Can I use the Panel Control instead of the PictureBox? It's very important for me to penning/zooming – Hakels May 20 '19 at 16:42
  • The above graphs are designed according to time. Charts are plotted between 00:05 and 01:10, as shown in the photo above. For example, to see the chart from 01:10 to 02:15, you must right-click with the mouse on the PictureBox and dart it to the left. Rendering is done slowly when dragging. Also, at the time of zooing – Hakels May 20 '19 at 16:52
  • What you describe sounds like scrolling, not resizing. Unless the actual data change you would never have to do any drawing at all, right? – TaW May 20 '19 at 18:04
  • I created a user control using a picturebox. This control is a graph that performs the zooming/penning operation. When I load the low data, it does not slow down, but it does slow down when we enter a lot of data into the graph. – Hakels May 20 '19 at 18:31
  • Ok, but still: How often do you draw? Only when new data are loaded or more often, eg when scrolling or zooming?? – TaW May 20 '19 at 20:07
  • This control I've created will be rendered again every time scrolling or zooming in, and this will slow down. Is there a way to render just once? Because the PictureBox Control can not scroll, it re-renders whenever a change control is made (zoom or scrolling). Some friends advise me to use a Panel Control instead of a photo that includes scrolling. – Hakels May 21 '19 at 04:33
  • I usually go [this way](https://stackoverflow.com/questions/4710145/how-can-i-get-scrollbars-on-picturebox): Set its Sizemode 1st to AutoSize, then to Zoom. __Nest the PBox in a Panel__ with Autoscroll=true. Now you can scroll the panel as if you were scrolling the pbox. And if you want to you can zoom in and out by changing the PBox size. Of course when zooming the quality of the image may suffer, but no more uneeded rendering.. – TaW May 21 '19 at 09:13

0 Answers0