c++ - 使用 graphics.h 的 Windows 错误

标签 c++ c windows graphics bgi

我正在尝试使用 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 指 Borland 的 MS DOS 图形库“BGI”。它仅受 Borland DOS 编译器支持,不能移植到其他操作系统,除了仍然支持 DOS 的旧 Windows 版本,如 Windows 95/98。

关于c++ - 使用 graphics.h 的 Windows 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32720085/

相关文章:

c++ - 如何解决 "pure virtual method called"

c++ - (C++) 需要使用 reg 找出半径内的所有点。二维窗口坐标。系统

c - scanf() 将换行符留在缓冲区中

c# - 在缺少 setup.py 的 Windows 上构建 Apache QPID

windows - 将所有批处理文件参数转发给内部命令

c++ - 在 C++ 98 中优化 vector 过滤

c++ - 我应该使用 const 来使对象线程安全吗?

c - __attribute__((packed)) 对嵌套结构数组的影响?

c - 三元运算符的奇怪枚举行为

windows - 从两组文本文件中提取唯一的行