天天看點

AGG第十四課 agg::conv_dash 渲染虛線1檔案引用和參數描述 2 使用經驗 3例子 4虛線的寬度 5取消虛線的抗鋸齒

檔案定義:include/agg_conv_dash.h

類定義:

  template<class VertexSource, class Markers=null_markers>

      conv_dash(VertexSource& vs) :

          conv_adaptor_vcgen<VertexSource, vcgen_dash, Markers>(vs)

注意:需要傳遞頂點源作為構造參數。

      void add_dash(double dash_len, double gap_len)

第一個參數是實線的長度,第二個參數是兩條實線之間的距離,通過建構若幹條相距gap_len的實線,達到虛線的效果

剛開始的時候,認為agg::conv_stroke和agg::conv_dash是互相沖突的,認為前者是渲染實線,後者是渲染虛線,實際上,前者是渲染任何圖形的輪廓線,虛線也是輪廓線的一種,隻不過是進行了拆分吧了!!

代碼如下:

              agg::path_storage ps1;

              ps1.move_to(200,200);

              ps1.line_to(1300,1300);

             agg::conv_dash<agg::path_storage>dash(ps1);

              //第一個參數是實線的長度,第二個參數是兩條實線之間的距離,通過建構若幹條

              //相距25的實線,達到虛線的效果

              dash.add_dash(5,25);//通不同的調整可以檢視到效果,如果是5,5

              //可能完全沒有任何的效果!!

             agg::conv_stroke<agg::conv_dash<agg::path_storage>>stroke(dash);

              //添加到渲染器中                     

              ras.add_path(stroke);

              //将線條渲染到記憶體圖檔當中,準備顯示

              agg::render_scanlines_aa_solid(ras,sl,renb,agg::rgba8(255,0,0));

              ras.reset();

如果目前的dash_len的長度比較短,可以取消抗鋸齒,加快渲染的速度,可以對比檢視效果嘗試使用stroke.width函數設定寬度無效,dash沒有提供設定線寬的函數

ras.gamma(agg::gamma_threshold(0.5));

例子如下:

  ras.reset();

  agg::path_storage ps;

  ps.move_to(30,40);

  ps.line_to(1300,1400);

  agg::conv_dash<agg::path_storage> dash(ps);

  dash.add_dash(10,30);

  agg::conv_stroke<agg::conv_dash<agg::path_storage>>stroke(dash);

  ras.add_path(stroke);

  //stroke.width(5);//測試線寬

  ras.gamma(agg::gamma_threshold(0.5));//測試抗鋸齒

  agg::render_scanlines_aa_solid(ras,sl,renb,agg::rgba8(255,0,0));

     本文轉自fengyuzaitu 51CTO部落格,原文連結http://blog.51cto.com/fengyuzaitu/1961383:,如需轉載請自行聯系原作者

繼續閱讀