關於C#雙緩沖處理(BufferedGraphicsContext對象)
阿新 • • 發佈:2018-07-23
tps color log this details 代碼 簡單 sco oca
https://blog.csdn.net/keep_silence_/article/details/7849880
https://blog.csdn.net/acs713/article/details/16359551
看了以上兩個網址總結一下吧,因為現在研究的是C#所以重點只放在C#的BufferedGraphicsContext對象身上。
按照第二個網址貼出的代碼會覆蓋原本的繪圖層出現 全部黑色背景。
總結兩段代碼
private void Show(Control control) { // 創建緩沖圖形上下文 BufferedGraphicsContext bct = newBufferedGraphicsContext(); // 創建指定大小緩沖區 BufferedGraphics bg = bct.Allocate(control.CreateGraphics(), new Rectangle(new Point (0,0),control.Size)); //創建GDI+畫圖區域 Graphics g = bg.Graphics; //清除背景顏色(變為默認背景顏色) g.Clear(this.BackColor);//跟平常Graphics繪圖一樣 Pen p = new Pen(Color.Red, 1); g.DrawRectangle(p,5,5,50,50); // 將雙緩沖區中的圖形渲染到指定畫布上 bg.Render(control.CreateGraphics()); //釋放 bg.Dispose(); g.Dispose(); }
重復可用,簡單。
關於雙緩沖原理解釋,上面第二個鏈接講得還是很通俗易懂的。
關於C#雙緩沖處理(BufferedGraphicsContext對象)