ubuntu

如何用Ubuntu CxImage调整图片大小

小樊
44
2025-09-14 23:19:45
栏目: 智能运维

在Ubuntu中使用CxImage调整图片大小,可参考以下步骤:

  1. 安装cxImage:打开终端,运行sudo apt updatesudo apt install libcximage-dev
  2. 编写代码:创建一个C++文件,如resize_image.cpp,包含头文件#include "cxImage.h",并编写代码加载图片、调整大小并保存,示例代码为:
#include <iostream>
#include "cxImage.h"
int main(int argc, char* argv[]) {
    if (argc != 4) {
        std::cerr << "Usage: " << argv[0<< " <input_image> <output_image> <width> <height>" << std::endl;
        return 1;
    }
    const char* inputImage = argv[1];
    const char* outputImage = argv[2];
    int width = std::atoi(argv[3]);
    int height = std::atoi(argv[4]);
    cxImage image;
    if (!image.Load(inputImage)) {
        std::cerr << "Failed to load image: " << inputImage << std::endl;
        return 1;
    }
    if (!image.Resize(width, height)) {
        std::cerr << "Failed to resize image." << std::endl;
        return 1;
    }
    if (!image.Save(outputImage)) {
        std::cerr << "Failed to save image: " << outputImage << std::endl;
        return 1;
    }
    std::cout << "Image resized and saved to: " << outputImage << std::endl;
    return 0;
}
  1. 编译代码:在终端中运行g++ resize_image.cpp -o resize_image -lcximage
  2. 运行程序:执行./resize_image input.jpg output.jpg 800 600,将input.jpg调整为800×600像素并保存为output.jpg

0
看了该问题的人还看了