我正在尝试使用 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/