图像访问器Image Accessor
也许有不少同学看到开头的线段生成器一节时,已经尝试修改示例代码中的span_image_filter_rgb_bilinear_clip了(比如改成span_image_filter_rgb_bilinear)。不过编译时会出错,这是因为大部分的线段生成器类接受的Source模板不是 PixelFormat Renderer,而是Image Accessor即图像存取器。
头文件
- #include <agg_image_accessors.h>
类型
- template<class PixFmt>
- class agg::image_accessor_clip // 图像以外的地方用指定颜色填充
- template<class PixFmt>
- class agg::image_accessor_clone // 图像以外的地方以图像边缘填充
- template<class PixFmt>
- class agg::image_accessor_no_clip // 图像以外不可读取,否则引发异常
- template<class PixFmt, class WrapX, class WrapY>
- class agg::image_accessor_wrap // 平铺图像,平铺方式由WrapX和WrapY指定
实验代码
把示例代码中的span_image_filter_rgb_bilinear_clip部分改成下面的代码
- ...
- // 线段生成器
- //typedef agg::span_image_filter_rgb_bilinear_clip<agg::pixfmt_bgr24,
- //interpolator_type > span_gen_type; // 这个就是Span Generator
- //span_gen_type span_gen(pixf_img, agg::rgba(0,1,0), ip);
- // 图像访问器
- typedef agg::image_accessor_clone<agg::pixfmt_bgr24> image_accessor_type;
- image_accessor_type accessor(pixf_img);
- // 使用span_image_filter_rgb_bilinear
- typedef agg::span_image_filter_rgb_bilinear<
- image_accessor_type,
- interpolator_type > span_gen_type;
- span_gen_type span_gen(accessor, ip);
- ...
建议把后面的ras.add_path(ell)改成ras.add_path(ccell)
显示效果

image_accessor_wrap类要指定WrapX和WrapY,可选的有:
wrap_mode_reflect wrap_mode_reflect_auto_pow2 wrap_mode_pow2 wrap_mode_repeat wrap_mode_repeat_auto_pow2 wrap_mode_repeat_pow2
比如我们把本例中的image_accessor_type定义改成
- //typedef agg::image_accessor_clone<agg::pixfmt_bgr24> image_accessor_type;
- typedef agg::image_accessor_wrap<agg::pixfmt_bgr24,
- agg::wrap_mode_reflect,agg::wrap_mode_repeat> image_accessor_type;
显示效果是

(为了突出效果,用矩阵img_mtx把源缩小了)
图像过滤器(Image Filter)
在一些线段生成器里,比如span_image_filter_[gray|rgb|rgba],span_image_resample_[gray|rgb|rgba]等类,它们的构造函数还有一个“const image_filter_lut &filter”参数,这个参数用于变换图像的像素值。它们的名称都以image_filter作为前缀,AGG中称为Image Filter(图像过滤器)。
头文件
- #include <agg_image_filters.h>
类型
- image_filter_bilinear;
- image_filter_blackman;
- image_filter_blackman[36|64|100|144|196|256];
- image_filter_kaiser;
- image_filter_lanczos;
- image_filter_lanczos[36|64|100|144|196|256];
- image_filter_mitchell;
- ...还有很多呢...
实验代码
把上面的span_image_filter_rgb_bilinear改成span_image_resample_rgb_affine
- ...
- //typedef agg::image_accessor_clone<agg::pixfmt_bgr24> image_accessor_type;
- typedef agg::image_accessor_wrap<agg::pixfmt_bgr24,
- agg::wrap_mode_reflect,agg::wrap_mode_repeat> image_accessor_type;
- image_accessor_type accessor(pixf_img);
- //typedef agg::span_image_filter_rgb_bilinear<
- // image_accessor_type,
- // interpolator_type > span_gen_type;
- //span_gen_type span_gen(accessor, ip);
- typedef agg::span_image_resample_rgb_affine<image_accessor_type> span_gen_type;
- span_gen_type span_gen(accessor, ip, agg::image_filter_sinc36());
- ...
显示效果