简体   繁体   English

Windows使用graphics.h错误

[英]Windows error using graphics.h

I am trying to use the graphics.h library for C/C++ to get pixel values from some images. 我正在尝试使用用于C / C ++的graphics.h库来从某些图像中获取像素值。 The program compiles without any errors or warnings but when I try to execute it, a window is opened with the following message: "version2.exe has encountered a problem and needs to close. We are sorry for the inconvenient". 程序编译时没有任何错误或警告,但是当我尝试执行该程序时,将打开一个窗口,其中显示以下消息:“ version2.exe遇到问题,需要关闭。对此给您带来的不便,我们深表歉意”。

My code: 我的代码:

#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 refers to the MS DOS graphics library "BGI", by Borland. graphics.h是指Borland的MS DOS图形库“ BGI”。 It is only supported by Borland DOS compilers and cannot get ported to another OS, save for the old Windows versions like Windows 95/98 that still supported DOS. 它仅受Borland DOS编译器支持,不能移植到其他OS,除非Windows 95/98之类的旧Windows版本仍支持DOS。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM