Windows 使用 graphics.h 时出错

Windows error using graphics.h

我正在尝试使用 graphics.h 库 C/C++ 从一些图像中获取像素值。该程序编译时没有任何错误或警告,但当我尝试执行它时,打开 window 并显示以下消息:"version2.exe has encountered a problem and needs to close. We are sorry for the inconvenient"。

我的代码:

#include <graphics.h>
#include <stdio.h>

/* Macros to set important values for
*  size and number of images
*/
#define IMAGES 9
#define WIDTH 200
#define HEIGTH 225

/* Receives the image number and load it using
 * readimagefile() function from BGI libary.
 */
void loadImage(int imageNumber);

int main(int argc, char const *argv[])
{
  int row, column, image;
  int red[HEIGTH][WIDTH][IMAGES], green[HEIGTH][WIDTH][IMAGES], blue[HEIGTH][WIDTH][IMAGES];
  int pixelValue;
  int finalWindow, currentWindow;


  for (image = 0; image < IMAGES; ++image)
  {
    currentWindow = initwindow(WIDTH, HEIGTH, "current"); // creates window to receive image
    setcurrentwindow(currentWindow); // set recent window as the current window
    loadImage(image);

    for (row = 0; row < HEIGTH; ++row)
    {
      for (column = 0; column < WIDTH; ++column)
      {
          pixelValue = getpixel(row, column);
          green[column][row][image] = GREEN_VALUE(pixelValue);
          red[column][row][image] = RED_VALUE(pixelValue);
          blue[column][row][image]= BLUE_VALUE(pixelValue);
      }
    }
  }

  getch();

  return 0;

}

void loadImage(int imageNumber)
{
 char str[5];
 sprintf(str, "%i.jpg", imageNumber);
 readimagefile(str, 0, 0, WIDTH, HEIGTH);
}

graphics.h 指 Borland 的 MS DOS 图形库 "BGI"。它仅受 Borland DOS 编译器支持,不能移植到另一个 OS,除了旧的 Windows 版本,如 Windows 95/98 仍然支持 DOS.

graphics.h 是 Borlando 编译器(例如 turbo c)在 1990 年代使用的库,现在该库非常过时并且不受主要编译器的支持。您可以使用 graphics.h 而不是由您的 compiler.graphic 函数定义的图形库函数因编译器而异,因为它们不是标准 c 语言的一部分,它们由不同的编译器以不同方式实现