How can a picture be displayed in the C language?

The C language itself does not support directly displaying images, but it can achieve this functionality using a graphics library. Below is an example code using a graphics library.

#include <graphics.h>

int main()
{
   int gd=DETECT,gm;
   initgraph(&gd,&gm,""); // 初始化图形界面

   // 读取图片文件,将图片显示在屏幕上
   readimagefile("image.jpg", 100, 100, 400, 400);

   getch(); // 等待用户按键,防止窗口关闭
   closegraph(); // 关闭图形界面

   return 0;
}

Please note that the above code requires a compiler supported by a graphics library. Turbo C++ compiler can be used in a Windows environment. Additionally, the image to be displayed should be placed in the same directory as the source code and named “image.jpg”. If you wish to display images in other formats, appropriate functions must be used to read that format of image file.

bannerAds