ubuntu

ubuntu cximage官方文档

小樊
39
2025-11-11 03:13:59
栏目: 智能运维

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 <iostream>
#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

Troubleshooting Common Issues

0
看了该问题的人还看了