SCADA实例解析四--SCADA画图和图象处理 -- 入门一

本文以非常简洁的 内存画布 + 画图API + 图象处理 结合的一个简单例子来介绍 SCADA在自画部分的 功能.

功能描述:

    本例子 首先在 SCADA窗体的自画事件中, 构建一个 内存画布, 用于画图API演示,    然后把画布转成 图象处理对象(DirectImage), 利用DirectImage的滤镜功能,  对图象添加噪声后, 显示出来.

 详细代码和注释如下:

 1 /*
 2     这是作者写的 演示 内存画布+图象处理 的例子. 
 3     
 4 paul
 5 2012-10-26.    
 6 */
 7 
 8 
 9 //  $$scadaWnd是 SCADA窗体对象, setEventProc方法是 定义SCADA窗体的事件处理. 
10 //   $$scadaWndGraph是     SCADA窗体在onPaint事件触发的时候, 设置的画图全局对象
11 $$scadaWnd->setEventProc( "onPaint", "onMyPaint($$scadaWndGraph);" ) ;
12 
13 // 重定义的画图方法. 
14 function onMyPaint( $graph )
15 {
16     // 调试输出, release版本中可以用 DebugView工具看输出信息. 
17     trace "onMyPaint" ;
18 
19     // 创建一个 内存画布, 尺寸为(300,300)    
20     $memGraph = GDI::newMemGraphics( 300, 300 ) ;    
21 
22     // 在这个画布中 随便画点东西, 演示画图API( 可参考GDI+的API, 因为本SCADA画图部分主要包装了 GDI+的 api )
23     $pen   = GDI::newPen( "red", 2 ) ;
24     $brush = GDI::newSolidBrush( "white" ) ;
25     $memGraph->fillEllipse( $brush, 0,0, 300, 300 ) ;
26     $memGraph->drawEllipse( $pen, 100,100, 100, 100 ) ;
27 
28     // 把 内存画布 转成 DirectImage对象( 因DirectImage对象中包含了图象处理的API ).  
29     $dimg = $memGraph->toDirectImage() ;
30     
31     // 图象滤镜处理示例: 噪声处理. 
32     $dimg->noise(100) ;
33     
34     // 转成bitmap对象( 以用来画图 ). 
35     $img  = $dimg->toBitmap() ;
36     
37     // 画图. 
38     $graph->drawImage( $img, 10, 10 ) ;
39 
40 }

效果:
  

 

 

 

 

posted on 2012-10-26 12:12  smartfish_liu  阅读(2196)  评论(1编辑  收藏  举报

导航