agg::conv_clip_polygon裁剪区域异常

头文件

#include"agg/include/agg_conv_clip_polygon.h"

简单实例代码

 void ClipPathByPolygon()

  {

   agg::rendering_buffer &rbuf = rbuf_window();

   agg::pixfmt_bgr24 pixf(rbuf);

 

   typedef agg::renderer_base<agg::pixfmt_bgr24> renderer_base_type;

   renderer_base_type renb(pixf);

 

   typedef agg::renderer_scanline_aa_solid<renderer_base_type>renderder_scanline_type;

   renderder_scanline_type rensl(renb);

 

   agg::rasterizer_scanline_aa<> ras;

   agg::scanline_u8 sl;

   ras.reset();

 

   agg::path_storage ps;

   ps.move_to(100,540);

   ps.line_to(168.889,471.429);

   ps.line_to(237.778,402.857);

   ps.line_to(306.667,334.286);

   ps.line_to(651.111,-8.57143);

   ps.line_to(720,-6.85714e+19);

   ps.line_to(200,400);

   ps.line_to(400,400);

   ps.line_to(200,500);

   ps.line_to(700,400);

 

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

   dash.add_dash(10,10);

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

   stroke.width(2);

 

   agg::conv_clip_polygon<agg::conv_stroke<agg::conv_dash<agg::path_storage>> > clip(stroke);

   clip.clip_box(0,0,600,800);

   ras.add_path(clip);

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

  }

结论:程序冻结!!

摘自:http://sourceforge.net/p/vector-agg/mailman/vector-agg-general/?viewmonth=200602&page=0


尝试放弃渲染虚线,正常:

    agg::path_storage ps;

    ps.move_to(100,540);

    ps.line_to(168.889,471.429);

    ps.line_to(237.778,402.857);

    ps.line_to(306.667,334.286);

    ps.line_to(651.111,-8.57143);

    ps.line_to(720,-6.85714e+19);

    ps.line_to(200,400);

    ps.line_to(400,400);

    ps.line_to(200,500);

    ps.line_to(700,400);


    agg::conv_stroke<agg::path_storage> stroke(ps);

    stroke.width(2);


    agg::conv_clip_polygon<agg::conv_stroke<agg::path_storage > > clip(stroke);

    clip.clip_box(0,0,600,800);

    //ras.clip_box(0,0,600,800);

    ras.add_path(stroke);

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


尝试采用ras的裁剪也没有问题!!

摘自作者:

I suspect you need to use clipping.
Call theRasterizer->clip_box(0,0, 800,600);
But the problem is that the rasterizer in agg23 clips everything in integers,
24.8 (8 bits for fractional part). So that, with 1e20 there will be overflow.
To avoid it you can use conv_clip_polygon:

typedef agg::conv_dash<path_t> dash_t;
typedef agg::conv_stroke<dash_t> stroke_t;
typedef agg::conv_clip_polygon<stroke_t> clipped_t;
. . .
(don't forget to call clipped_t::clip_box())



你可能感兴趣的:(clip,agg,conv)