图案填充失败

#include "platform/agg_platform_support.h"

#include "agg_basics.h"

#include "agg_rendering_buffer.h"

#include "agg_pixfmt_rgb.h"

#include "agg_alpha_mask_u8.h"

#include "agg_pixfmt_amask_adaptor.h"

#include "agg_rasterizer_scanline_aa.h"

#include "agg_scanline_u.h"

#include "agg_renderer_scanline.h"

#include "agg_ellipse.h"

#include "agg_conv_contour.h"

#include "agg_conv_stroke.h"

#include "agg_conv_dash.h"

#include "agg_conv_transform.h"


#include "platform/win32/agg_win32_bmp.h"

#include "agg_span_allocator.h"

#include "agg_span_image_filter_rgb.h"

#include "agg_span_interpolator_trans.h"

#include "agg_span_interpolator_persp.h"

#include "agg_span_interpolator_linear.h"

enum { flip_y = true};

class the_application : public agg::platform_support

{

public:

  the_application(agg::pix_format_e format, bool flip_y):

      agg::platform_support(format,flip_y)

      {}

      virtual ~the_application()

      {

      }

      virtual void on_init(){}

      virtual void on_draw()

      {

        unsigned i;

        //renderer buffer

        agg::rendering_buffer rbuf = this->rbuf_window();

        //renderers

        agg::pixfmt_bgr24 pixf(rbuf);//底层像素渲染对象,对渲染内存进行包装了


        typedef agg::renderer_base<agg::pixfmt_bgr24> ren_base_type;//底层渲染器

        ren_base_type ren_base(pixf);

        ren_base.clear( agg::rgba8(255,255,255) );//清除buffer背景色

        typedef agg::renderer_scanline_aa_solid<ren_base_type> renderer_scanline_type;//高层渲染器

        renderer_scanline_type ren_scanline(ren_base);


        //装载图案作为生成span生成器的source

        agg::pixel_map pm_img;//可以load进bitmap

        pm_img.load_from_bmp("d://hello.bmp");

        //构建图案的renderer

        agg::rendering_buffer rbuf_img( pm_img.buf(), pm_img.width(), pm_img.height(),pm_img.stride() );

        agg::pixfmt_rgb24 pixf_img(rbuf_img);

        //线段分配器

        typedef agg::span_allocator<agg::rgba8> span_allocator_type;

        span_allocator_type span_alloc;

        //透视变换的插值器

        typedef agg::span_interpolator_persp_lerp<> span_interp_type;

        const double offset(0);

        const double scale(0.1);

        double src[8] = {offset,offset,

          offset+pixf_img.width()*scale, offset,

          offset+pixf_img.width()*scale, offset+pixf_img.height()*scale,

          offset, offset+pixf_img.height()*scale};

        double dest[8] = {0,0-180,

          pixf.width(), 0-180,

          pixf.width(), pixf.height()-180,

          0, pixf.height()-180};

        span_interp_type span_interp(src,dest);

        //span生成器,使用图案作为span生成器

        typedef agg::span_image_filter_rgb_bilinear_clip<agg::pixfmt_rgb24,span_interp_type> span_gen_type;

        span_gen_type span_gen(pixf_img, agg::rgba8(255,255,255), span_interp);


        //组合成渲染器

        agg::renderer_scanline_aa< ren_base_type, span_allocator_type, span_gen_type > img_renderer(ren_base, span_alloc, span_gen);


        //vertex source

        agg::ellipse ell(0,0, 120, 90);//定义一个圆vertex source

        //vertex source 仿射变换

        agg::trans_affine imx;

        imx.translate(150, 150);

        typedef agg::conv_transform<agg::ellipse> ell_ct_type;

        ell_ct_type ctell(ell, imx);


        //轮廓

        typedef agg::conv_contour<ell_ct_type> ell_cc_type;

        ell_cc_type ccell(ctell);

        //

        typedef agg::conv_stroke<ell_ct_type> ell_cs_type;

        ell_cs_type csccell(ctell);

        csccell.width(1);//con_stroke的width属性决定线宽度


        agg::rasterizer_scanline_aa<> ras;//Polygon rasterizer, which including a clipper

        agg::scanline_u8 sl;//非封装扫描线容器,rasterizer use it to render the render_buffer


        //使用图案填充

        ras.add_path(ctell);

        agg::render_scanlines( ras, sl, img_renderer );


        //椭圆轮廓线

        ras.add_path(csccell);//添加路径

        ren_scanline.color( agg::rgba8(50,40,23) );

        agg::render_scanlines( ras, sl, ren_scanline );//ras使用sl中的span渲染ren_scanline

      }

};


int agg_main(int argc, char* argv[])

{

  the_application app(agg::pix_format_bgr24, flip_y);

  app.caption("My AGG Demo");

  if(app.init(300, 300, agg::window_resize ))

  {

    app.run();

  }

  return 1;

}


摘自:http://blog.csdn.net/erikliu/article/details/6232764

提出如下的几点疑问:

1)是否跟AGG的版本有关,目前使用了2.4,2.5版本无效!!

2) 是否跟图片的像素有关??

3)是否有例子支持,源码下没有任何的例子支持!!

你可能感兴趣的:(agg,.load_from_bmp)