代码
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_bin_solid<renderer_base_type> renderder_scanline_type;
renderder_scanline_type rensl(renb);
agg::rasterizer_scanline_aa<> ras;
agg::scanline_u8 sl;
ras.reset();
renb.clear(agg::rgba8(255,255,255));
agg::gsv_text txt;
agg::conv_stroke<agg::gsv_text> txtStroke(txt);
txtStroke.width(3);
txtStroke.line_cap(agg::square_cap);
txt.flip(true);//Windows下坐标轴是反转的
txt.size(20);//文字的尺寸
txt.line_space(10);//gsv_text能够处理\n换行,设置每一行之间的间距
txt.space(10);//字符之间的间距
txt.start_point(100, 300);//文字的起始位置,实际上是有偏差的,需要进行微调
txt.text("http://fengyuzaitu.blog.51cto.com\nhttp://fengyuzaitu.blog.51cto.com");
ras.add_path(txtStroke);
agg::render_scanlines_aa_solid(ras,sl,renb,agg::rgba8(255, 0, 0));
ras.reset();
注意:
1 只支持渲染ASCII字符
2 只能够横向字符的渲染