How to prevent graphical stutter when scrolling a large zoomed out picture

后端 未结 1 1738
余生分开走
余生分开走 2021-01-25 08:56

I have a large TIFF picture (5.9 MB, 13k X 16k resolution) that the user loads into a scrollable panel that he then can zoom in/out of, scroll and mark points, regions etc. on.<

相关标签:
1条回答
  • 2021-01-25 09:30

    Is not tested, but should give an idea.

    Bitmap _cached = null;
    
    override void OnPaint(PaintEventArgs e)
    {
        if(_cached == null)
        {
            _cached = new Bitmap(this.ClientSize.Width, this.ClientSize.Height);
            using(var graphics = Graphics.FromImage(_cached)
            {
                 // draw into this graphics once -> it will be cached in _cached bitmap
            }
        }
        e.Graphics.DrawImage(_cached, Point.Empty);
    }
    
    // call this if _zoom or ClientSize is changed
    void ResetCache()
    {
        _cache = null;
        this.Invalidate(); // mandatory for _zoom change
    }
    

    Also, I don't know how to do you present your zoomed-in picture, but usually there is an offset so that you can move (pan) image.

    0 讨论(0)
提交回复
热议问题