Windows错误使用图形.h

Windows error using graphics.h

本文关键字:图形 错误 Windows      更新时间:2023-10-16

我试图使用C/c++的graphics.h库从一些图像中获得像素值。程序编译没有任何错误或警告,但当我尝试执行它时,打开一个窗口,显示以下消息:"version2.exe遇到问题,需要关闭。"给您带来不便,我们深表歉意。"

我代码:

#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指MS DOS图形库"BGI",由Borland提供。它只支持Borland DOS编译器,不能移植到其他操作系统,除了旧的Windows版本,如Windows 95/98仍然支持DOS。

graphics.h是Borlando编译器(例如turbo c)在20世纪90年代使用的库,现在该库非常过时,并且不被主要编译器支持。您可以使用编译器定义的图形库函数来代替graphics.h。图形函数因不同的编译器而不同,因为它们不是标准c语言的一部分,它们在不同的编译器中实现不同