在 Debian 系统下使用 CxImage(一个 C++ 图像处理库),通常需要先安装/编译它,然后在你的 C++ 项目中调用。下面按常见方式说明。
Debian 官方仓库一般没有现成的 cximage 包,常见做法是源码编译。
sudo apt update
sudo apt install build-essential git
获取源码(示例,可用任意可信来源):
git clone https://github.com/antaressoftware/cximage.git
cd cximage
编译:
make
或(视项目结构):
g++ -I. -I./ximage yourcode.cpp *.cpp -o test
编译完成后你会得到:
*.hlibcximage.a 或 .o 文件可复制到系统目录(可选):
sudo cp *.h /usr/local/include/
sudo cp libcximage.a /usr/local/lib/
#include <ximage.h>
#include <iostream>
int main() {
CxImage image;
if (image.Load("test.jpg", CXIMAGE_FORMAT_JPG)) {
std::cout << "Width: " << image.GetWidth() << std::endl;
std::cout << "Height: " << image.GetHeight() << std::endl;
image.GrayScale();
image.Save("gray.jpg", CXIMAGE_FORMAT_JPG);
} else {
std::cout << "Load failed" << std::endl;
}
return 0;
}
g++ test.cpp *.cpp -I. -o test -lpthread
g++ test.cpp -lcximage -L/usr/local/lib -I/usr/local/include -o test
确保 -I 指向 CxImage 头文件目录。
libcximage.a-lpthreadCxImage 对 JPG/PNG/BMP 支持较好,特殊格式需启用对应宏。
在 Debian 使用 CxImage 的核心步骤:
ximage.hCxImage 类加载/处理/保存图像如果你愿意,可以告诉我:
我可以给你更精确的示例。