Installing CXImage on Ubuntu
To use CXImage on Ubuntu, start by installing essential compilation tools and image format dependencies. Open a terminal and run:
sudo apt update && sudo apt upgrade -y
sudo apt install build-essential cmake libpng-dev libjpeg-dev libtiff-dev libgif-dev -y
These commands install GCC, CMake, and libraries required for handling PNG, JPEG, TIFF, and GIF formats.
Downloading CXImage Source Code
CXImage’s source code is hosted on GitHub. Clone the official repository (or a stable branch like main) using Git:
git clone https://github.com/cximage/cximage.git
cd cximage
Switch to the desired branch if necessary (e.g., git checkout main).
Compiling and Installing CXImage
Use CMake to generate build files and compile the source code:
mkdir build && cd build
cmake .. # Configure the build system
make -j$(nproc) # Compile with all available CPU cores
sudo make install # Install to system directories (/usr/local/include, /usr/local/lib)
This process compiles CXImage and installs it system-wide.
Configuring Environment Variables
To ensure your compiler locates CXImage’s headers and libraries, add the following to your ~/.bashrc (or ~/.zshrc):
export CPLUS_INCLUDE_PATH=/usr/local/include:$CPLUS_INCLUDE_PATH
export LIBRARY_PATH=/usr/local/lib:$LIBRARY_PATH
Run source ~/.bashrc to apply changes immediately.
Verifying Installation
Check if CXImage is installed correctly by compiling a test program. Create test_load_save.cpp:
#include
#include "cximage.h"
int main() {
CXImage image;
if (!image.Load("input.jpg", CXIMAGE_FORMAT_JPG)) {
std::cerr << "Failed to load image!" << std::endl;
return 1;
}
if (!image.Save("output.png", CXIMAGE_FORMAT_PNG)) {
std::cerr << "Failed to save image!" << std::endl;
return 1;
}
std::cout << "Image converted successfully!" << std::endl;
return 0;
}
Compile and run:
g++ test_load_save.cpp -o test_load_save -lcximage
./test_load_save
If successful, this converts a JPEG to PNG and prints confirmation messages.
Basic Usage Examples
- Loading/Saving Images: The test program above demonstrates core functionality—loading an image and saving it in a different format.
- Image Manipulation: Resize an image to 800x600 pixels with
image.Resize(800, 600, FILTER_BOX)(fast resizing), rotate 90 degrees clockwise withimage.Rotate(90), or crop a 300x300 region starting at (100, 100) withimage.Crop(100, 100, 400, 400).
Troubleshooting Common Issues
- Missing Dependencies: If compilation fails, ensure all required libraries (e.g.,
libpng-dev,libjpeg-dev) are installed. - Library Path Errors: If you get “undefined reference” errors, verify that
/usr/local/libis inLIBRARY_PATHand/usr/local/includeis inCPLUS_INCLUDE_PATH. - Custom Installation Paths: If you installed CXImage to a non-standard directory (e.g.,
/opt/cximage), specify paths during compilation with-I/opt/cximage/includeand-L/opt/cximage/lib.
以上就是关于“ubuntu cximage官方文档”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm