BITMAPINFO binf = {0};
binf.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
binf.bmiHeader.biWidth = 100;
binf.bmiHeader.biHeight = -100;
binf.bmiHeader.biPlanes = 1;
binf.bmiHeader.biBitCount = 32;
binf.bmiHeader.biCompression = BI_RGB;
binf.bmiHeader.biSizeImage = 0;
void* pBmpBits = NULL;  // Will be freed by DeleteObject(hBmp)
HBITMAP hBmp = CreateDIBSection(NULL, &binf, DIB_RGB_COLORS, &pBmpBits, NULL, NULL);agg::rendering_buffer aggbuf((unsigned char*)pBmpBits, 100, 100, 400);
typedef agg::renderer_base<agg::pixfmt_bgr24> ren_base;
agg::pixfmt_bgr24 pixf(aggbuf);
ren_base ren(pixf);ren.clear(agg::rgba(1,1,1));
agg::scanline_u8 sl;agg::rasterizer_scanline_aa<> ras;
agg::path_storage ps;agg::conv_stroke<agg::path_storage> pg(ps);
pg.width( 1);ps.remove_all();ps.move_to(0, 0);
ps.line_to(100, 0);  
// 此句让人非常费解,这里的参数(为double型)难道指的不是一个像素?
// 我用CDC的MoveTo和LineTo调用
dc.MoveTo(0, 0);
dc.LineTo(100, 0);
// 此时发现dc画的线要比AGG画的长一些,不知道这是怎么回事?
AGG里面的一个像素难道与CDC里面的的不同?
要怎么把AGG里面的长度转换成CDC里面的长度?请高手指点下,谢谢.

解决方案 »

  1.   

    ps.move_to(0, 0); 
    ps.line_to(100, 0);  
    // 此句让人非常费解,这里的参数(为double型)难道指的不是一个像素? 坐标又不是长度,不可以为double的吗? 我觉得用double更精确些。
      

  2.   

    AGG支持亚像素精度。这应该是一个原因。
      

  3.   

    你能不能给我说下如何在mfc中使用agg呢?
    我把agg编译成静态链接库,做个Win32程序运行Damo是没有问题的
    可是如何把agg放到mfc中呢?
    我把.h文件和lib文件放入mfc项目文件夹中,再link了lib文件,在OnDraw中画了条线。报错如下:hdc_renderer.obj : error LNK2005: "public: void __thiscall hdc_renderer::color(struct agg::rgba8)" (?color@hdc_renderer@@QAEXUrgba8@agg@@@Z) already defined in mfcView.obj
    hdc_renderer.obj : error LNK2005: "private: void __thiscall hdc_renderer::draw_solid_span(int,int,int)const " (?draw_solid_span@hdc_renderer@@ABEXHHH@Z) already defined in mfcView.obj
    hdc_renderer.obj : error LNK2005: "private: void __thiscall hdc_renderer::blend_pixel(int,int,unsigned int)const " (?blend_pixel@hdc_renderer@@ABEXHHI@Z) already defined in mfcView.obj
    LINK : warning LNK4098: defaultlib "LIBCD" conflicts with use of other libs; use /NODEFAULTLIB:library
    agg.lib(agg_platform_support.obj) : error LNK2001: unresolved external symbol "int __cdecl agg_main(int,char * * const)" (?agg_main@@YAHHQAPAD@Z)
    Debug/mfc.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.mfc.exe - 5 error(s), 1 warning(s)
      

  4.   

    agg太难用了,用这个吧,简单高效,功能强大。
    http://picasso-graphic.googlecode.com/files/picasso_0.9_beta1.zip
      

  5.   

    Picasso 矢量图型库更新 
    http://code.google.com/p/picasso-graphic/