摘 要:針對實時系統中對圖形繪制速度的特殊要求,提出一種應用于Windows環境下應用程序客戶區中的高效圖形繪制算法,給出實現圖形水平平移、豎直平移、自由平移、水平縮放、豎直縮放、自由縮放的關鍵技術。該算法基于無效矩形確定圖形中需要繪制的數據和坐標軸范圍,可避免大量不必要的重繪工作,實現圖形高效、快速繪制,保證操作的實時性。利用內存DC繪圖可避免圖形閃爍,增強圖形顯示效果。與Matlab中繪圖函數進行性能比較,證明了提出的圖形繪制算法是有效的。關鍵詞:圖形繪制; 無效矩形; 圖形閃爍; Matlab
中圖分類號:TN911-34; TP3111文獻標識碼:A
文章編號:1004-373X(2010)16-0043-04
Real-time and Efficient Graphics-drawing Algorithm under Windows Condition
ZHANG Zhi-min, OU Jian-ping, HUANG Fu-kan
(College of Electronic Science and Engineering, National University of Defense Technology, Changsha 410073, China)
Abstract: An efficient graphics-drawing algorithm applied to the client area of Windows system is proposed to meet the requirement of real-time systems. The key technologies which can realize the patterns′ horizontal displacement, vertical translation, unconstrained translation, image horizontal scaling, image vertical scaling and image unconstrained scaling are presented. The data and axis scale which need to be drawed in graphics are determined with the algorithm by utilizing the invalid rectangle to avoid lots of unnecessary redrawing and realize efficient and fast graphics-drawing. With the memory DC, graphics flicker is avoided, as a result, the vividness of graphics is enhanced. In comparison with the plot function in Matlab, simulation results show that the algorithm proposed in this paper is efficient.Keywords: graphics drawing; invalid rectangle; graphics flicker; matlab
0 引 言
隨著計算機科學技術的飛速發展,計算機已經深入到各行各業,人類也隨著發展產生了大量的信息數據,這些信息數據為生產和研究提供了依據。在分析過程中,以圖形方式顯示數據可以達到直觀的效果,給決策人以感官上的啟發[1-3]。例如在無線電工程等領域,經常需要以圖形化方式監視無線通信信號的時域波形、頻譜波形等[4]。為便于獲取包含于數據中的更詳細的信息,要求操作人員監視信號時能隨時察看圖形的局部細節,即要求圖形具有水平縮放、豎直縮放、自由縮放、水平平移、豎直平移、自由平移等功能,而且所有這些對圖形的操作都要求能實時進行[5],這就給圖形顯示程序的設計帶來一定難度。
Windows操作系統提供了圖形設備接口(GUI)[6-8]。在Windows操作系統中,當移動某個應用程序窗口的位置,致使窗口原來被遮蓋的部分顯露出來,或者改變窗口大小時,Windows都要向應用程序發送WMPAINT消息,以告知應用程序有一部分客戶區域已變為無效,需要重新繪制,即重繪。……