在 Debian 上集成 CxImage(一个 C++ 图像处理库)进行开发,通常有两种方式:
下面以 Debian 11/12 为例,讲清楚从获取到使用的完整流程。
sudo apt update
sudo apt install -y build-essential g++ make git
如果需要 PNG / JPG / TIFF 支持,建议安装:
sudo apt install -y libpng-dev libjpeg-dev libtiff-dev
CxImage 官方已不再活跃维护,常见来源:
git clone https://github.com/ata4/cximage.git
cd cximage
从 http://www.xdp.it/cximage.htm 下载并解压。
cd cximage
典型目录结构:
CxImage/
├── CxImage/
├── jpeg/
├── png/
├── tiff/
├── zlib/
└── Makefile
make
如果成功,会生成:
libcximage.a
(部分版本可能需要 make -f Makefile.linux)
myproject/
├── main.cpp
├── include/
│ └── CxImage/
└── lib/
└── libcximage.a
复制头文件和库:
cp -r cximage/CxImage/*.h myproject/include/CxImage/
cp cximage/libcximage.a myproject/lib/
#include <CxImage.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;
} else {
std::cout << "Load failed" << std::endl;
}
return 0;
}
g++ main.cpp -Iinclude \
-Llib -lcximage \
-lpng -ljpeg -ltiff -lz \
-o myproject
运行:
./myproject
确认:
#include <CxImage.h>
并且 -Iinclude 路径正确。
说明库顺序不对,确保:
-lcximage -lpng -ljpeg -ltiff -lz
可在编译时加:
-std=c++11
⚠️ 注意
CxImage:
替代方案(更现代):
libopencv-dev)libfreeimage-dev)如果你愿意,我可以:
你打算用在什么场景?(图像格式转换 / 界面显示 / 服务器处理)