BGI ERROR :Graphics not initialized(use 'initgraph) 程序在调用initgraph()函数进行图形初始化时,没有将相应的动文件(*bgi)装入程序执行
那么请问,怎么装入执行呢?
将bgi驱动注册到程序中的方法:
1、在bgi目录下找到bgiobj.exe这个程序,若你想把EGAVGA.bgi转换成EGAVGA.obj在命令行输入bgiobj EGAVGA
2、将生成egavga.obj添加到graphics.lib中,使用命令tlib graphic +egavga
(注:向graphics.lib添加字体也是同样方法,用bgiobj将字体文件*.chr转换成.obj)
上述两部完成以后可以写程序使用了:
/* 该程序摘自BC3.1的帮助手册 */
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
/* register a driver that was added into graphics.lib */
/* For information on adding the driver, see the
/* BGIOBJ section of UTIL.DOC */
errorcode = registerbgidriver(EGAVGA_driver);
/* report any registration errors */
if (errorcode < 0)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
/* draw a line */
line(0, 0, getmaxx(), getmaxy());
/* clean up */
getch();
closegraph();
return 0;
}
若对于注册图形驱动有问题,请查看util.doc文件,没有util.doc下载以下附件
奇怪了,,你的代码我复制了,可以运行,为什么我的就不行呢?你给看看吧:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
/* 此处添加你自己的代码 */
int graphdriver=DETECT;
int graphmode,x,y;
detectgraph(&graphdriver,&graphmode);
initgraph(&graphdriver,&graphmode,"");
cleardevice();
for(y=20;y<200;y+=20)
{
for(x=20;x<=400;x+=12)
{
setcolor(GREEN);
line(x,y,x+4,y);
putpixel(x+8,y,YELLOW);
}
}
getch();
closegraph();
return 0;
}