我正在尝试使用用于 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);
}