How to output a jpg image in C language?

In C programming language, to display a jpg image, you can use image processing libraries like OpenCV.

Firstly, you need to install the OpenCV library and include relevant header files in your code.

#include <stdio.h>
#include <opencv2/opencv.hpp>

using namespace cv;

int main() {
    // 读取jpg图片
    Mat image = imread("image.jpg");

    // 判断图片是否成功读取
    if (image.empty()) {
        printf("Failed to read image.\n");
        return -1;
    }

    // 创建窗口并显示图片
    namedWindow("Output Image", WINDOW_NORMAL);
    imshow("Output Image", image);

    // 等待按下任意键后关闭窗口
    waitKey(0);
    destroyAllWindows();

    return 0;
}

In the code above, the jpg image is first read using the imread function, then a window for displaying the image is created using the namedWindow function, and the image is displayed in the window using the imshow function.

Lastly, use the waitKey function to wait for the user to press any key before closing the window, and use the destroyAllWindows function to destroy the window.

Please note that the above code requires linking the OpenCV library to the project during compilation and linking. Specific compilation and linking methods can be found in the OpenCV documentation or related tutorials.

bannerAds