Agg在Windows下的编译与使用

flyfish

Agg简介
AGG(Anti-Grain Geometry)是一个开源免费的图形库。

官网地址: www.antigrain.com

主要是编译称为Lib库,然后提供给其他程序使用
环境:
Win10 x64
Visual Studio 2013
字符集 Unicode

下载已经编译好Lib的库的地址(包含源码)

函数替换
sprintf sprintf_s
strcpy strcpy_s
fopen fopen_s
等 就是一些不安全的函数更改为安全的函数

新建一个 Win32 项目,应用类型是 静态库
将src中文件添加到项目中,如图,帅选器也和目录结构一样

添加文件时,不添加agg_platform_support.cpp,因为该代码时在字符集是多字节下编写的,如果编译环境使用多字节,可以添加该文件

配置如下
1配置属性-》常规-》字符集:使用Unicode字符集
2 C/C++->常规-》附加包含目录
./include;./font_freetype;./font_win32_tt;./gpc;
3 C/C++ -》预编译头:不使用预编译头

编译生成Lib

MFC下的使用
新建一个基于对话框的项目

以Agg源码在F:\Lib下为例
配置如下
1 C/C++ -》常规-》附加包含目录F:\lib\Agg\Agg\include;
2 链接器-》附加库目录:F:\lib\Agg\Debug;
3 链接器-》输入-》附加依赖项:agg.lib

代码
主要是在对话框的OnPaint中编写

void CAggTestDlg::OnPaint()
{if (IsIconic()){CPaintDC dc(this); // 用于绘制的设备上下文SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);// 使图标在工作区矩形中居中int cxIcon = GetSystemMetrics(SM_CXICON);int cyIcon = GetSystemMetrics(SM_CYICON);CRect rect;GetClientRect(&rect);int x = (rect.Width() - cxIcon + 1) / 2;int y = (rect.Height() - cyIcon + 1) / 2;// 绘制图标dc.DrawIcon(x, y, m_hIcon);}else{RECT rt;GetClientRect(&rt);int width = rt.right - rt.left;int height = rt.bottom - rt.top;//============================================================ //Creating compatible DC and a bitmap to render the image BITMAPINFO bmp_info;bmp_info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);bmp_info.bmiHeader.biWidth = width;bmp_info.bmiHeader.biHeight = height;bmp_info.bmiHeader.biPlanes = 1;bmp_info.bmiHeader.biBitCount = 32;bmp_info.bmiHeader.biCompression = BI_RGB;bmp_info.bmiHeader.biSizeImage = 0;bmp_info.bmiHeader.biXPelsPerMeter = 0;bmp_info.bmiHeader.biYPelsPerMeter = 0;bmp_info.bmiHeader.biClrUsed = 0;bmp_info.bmiHeader.biClrImportant = 0;HDC hdc = ::GetDC(m_hWnd);HDC mem_dc = ::CreateCompatibleDC(hdc);void* buf = 0;HBITMAP bmp = ::CreateDIBSection(mem_dc,&bmp_info,DIB_RGB_COLORS,&buf,0,0);// Selecting the object before doing anything allows you // to use AGG together with native Windows GDI.HBITMAP temp = (HBITMAP)::SelectObject(mem_dc, bmp);//============================================================ // AGG lowest level code.agg::rendering_buffer rbuf;rbuf.attach((unsigned char*)buf, width, height, -width * 4); // Use negative stride in order// to keep Y-axis consistent with// WinGDI, i.e., going down.// Pixel format and basic primitives rendereragg::pixfmt_bgra32 pixf(rbuf);agg::renderer_base<agg::pixfmt_bgra32> renb(pixf);renb.clear(agg::rgba8(255, 255, 255, 255));// Scanline renderer for solid filling.agg::renderer_scanline_aa_solid<agg::renderer_base<agg::pixfmt_bgra32> > ren(renb);// Rasterizer & scanlineagg::rasterizer_scanline_aa<> ras;agg::scanline_p8 sl;// Polygon (triangle)ras.move_to_d(20.7, 34.15);ras.line_to_d(398.23, 123.43);ras.line_to_d(165.45, 401.87);// Setting the attrribute (color) & Renderingren.color(agg::rgba8(80, 90, 60));agg::render_scanlines(ras, sl, ren);//============================================================//------------------------------------------------------------ // Display the image. If the image is B-G-R-A (32-bits per pixel)// one can use AlphaBlend instead of BitBlt. In case of AlphaBlend// one also should clear the image with zero alpha, i.e. rgba8(0,0,0,0)::BitBlt(hdc,rt.left,rt.top,width,height,mem_dc,0,0,SRCCOPY);// Free resources ::SelectObject(mem_dc, temp);::DeleteObject(bmp);::DeleteObject(mem_dc);CDialogEx::OnPaint();}
}

效果

Agg在Windows下的编译与使用相关推荐

  1. Boost在Linux和windows下的编译 32位 64位

    一 简言 1. Boost库是一个可移植.提供源代码的C++库,作为标准库的后备,是C++标准化进程的开发引擎之一 2. Boost官网地址:http://www.boost.org/ 3. 本博客示 ...

  2. tinyxml在linux和windows下的编译及使用详解

    一:摘要 1.XML全称EXtensible Markup Language,翻译为可扩展标记语言,XML文件通常就是一个文本文件,可以使用任何编码 2.TinyXML是一个开源的C++用来处理XML ...

  3. jsoncpp在linux和windows下的编译及使用详解

    一:摘要 1. JSON是一种轻量级的数据传输格式,全称为:JavaScript Object Notation,官方网址: http://www.json.org/json-zh.html 3. J ...

  4. Windows下MinGW编译vim7.4

    学习了一段时间Vim,感觉有些功能真的很方便.因学习原因,工作平台更换到一台老式Xp电脑上,重新安装了Vim7.4.官网默认版本不支持等宽字体和GDI++渲染,需要手工编译一个修改过的版本. 1.下载 ...

  5. ncnn环境搭建一 - windows下protobuf编译安装

    1. 环境 安装环境采用visual studio 2015 + protobuf 3.4.0 + ncnn 2. visual studio 2015安装 visual studio采用的是 vs2 ...

  6. 【转载】【VSCode】Windows下VSCode编译调试c/c++

    转载自:http://blog.csdn.net/c_duoduo/article/details/51615381 懒得自己配置或自己配置出现不明问题的朋友可以点这里:  [VSCode]Windo ...

  7. windows下cmake编译VTK到PCL中

    补充: 如果嫌编译麻烦,这里可以下载我编译好的:VTK-8.0.1,下载后直接拷贝到pcl安装目录下替换原VTK目录. 编译VTK的原因: pcl安装版中自带的vtk缺少QVTKWidget.dll, ...

  8. 开源的excel读取库libxls在windows下的编译,且支持中文,全网首发

    转载请注明出处:http://www.cnblogs.com/superbi/p/5482516.html 到目前为止,网络和官网上并没有关于libxls在windows下支持中文的教程,也没有现成的 ...

  9. VLC-3.0.0(Nightly版)在Linux和Windows下的编译步骤详解

    VLC 3.0.0 Compile vlc的编译一直是个大坑,做过音视频开发的不少人想必都踩过,开篇引用官方wiki一句话: Compiling VLC is not an easy task. 本文 ...

最新文章

  1. 面向固态激光雷达和惯导的里程计和建图
  2. jQuery的进行解决layui闪退的问题
  3. 【STM32】GPIO之蜂鸣器
  4. Sourcing Cockpit: 2. Demo of Service Purchase Order
  5. Visual Studio 2010 旗舰版安装图解
  6. 【java】为什么HashMap桶中节点个数超过8才转为红黑树?
  7. 各大搜索引擎提交地址
  8. MYSQL-实现ORACLE- row_number() over(partition by ) 分组排序功能
  9. Java性能调优指南pdf阅读0-100页
  10. awk&sed替换字符串
  11. 支付宝签名php,支付宝快捷支付 PHP服务端签名
  12. 吴恩达老师深度学习视频课笔记:总结
  13. org.hibernate.ObjectNotFoundException: No row with the given identifier exis
  14. 如何从Windows 10注销其他用户
  15. 数据库备份与恢复,全备份、增量备份
  16. 计算机毕业设计选题\开题\项目\论文\答辩一套玩转毕业设计
  17. TNMT新交通排行榜
  18. 分析LogFilter
  19. 人脸识别准确概率计算——超详细
  20. springboot的log4j2日志不打印,且控制台不输出!!!

热门文章

  1. 【Linux学习随笔】三、Sheel语法-概论
  2. surface pro 7 linux,微软正式发布Surface Pro 7
  3. 好的开发信标题该怎么写这样写客户打开率高达90%
  4. 推荐一款免费的SQLsever的备份软件sqlBackupAndFtp
  5. 计算机网络应用智能家居,计算机智能化网络应用研究
  6. 数据结构Java --- 泛型
  7. 浮动( Floats )
  8. struct cred
  9. vue 单元测试报错之 undefined is not a constructor (evaluating 'expect(vmComponent.count).toBe(1)')
  10. 分析数学成绩,尽然我考了0分