CImg库介绍
CImg是一个跨平台的C++的图像处理库,提供了加载、处理、显示、保存等一系列功能,其中的图像处理功能尤其强大。
CImg库下载
下载地址:https://github.com/GreycLab/CImg,下载时注意应该下载源码包,里面附带的大量的例程。而实际上CImg库只是一个头文件CImg.h,这个头文件里包含了CImg库所有的代码。
CImg库使用
CImg无需编译,只需要包含头文件: #include “CImg.h” 以及命名空间:using namespace cimg_library;
CImg库demo:
#include "CImg.h"
using namespace cimg_library;
int main()
{
// 定义一个每个颜色 8 位(bit)的 640x400 的彩色图像
CImg<unsigned char> img(640, 400, 1, 3);
//将像素值设为 0(黑色)
img.fill(0);
// 定义一个紫色
unsigned char purple[] = { 255,0,255 };
// 在坐标(100, 100)处画一个紫色的“Hello world”
img.draw_text(100, 100, "Hello World", purple);
// 在一个标题为“My first CImg code”的窗口中显示这幅图像
img.display("My first CImg code");
return 0;
}
结果显示: