编程论坛's Archiver

hewenhao 发表于 2007-1-22 13:03

【求助】关于图形函数

<P>源程序如下:<br>#include &lt;graphics.h&gt; <br>#include &lt;stdlib.h&gt; <br>#include &lt;stdio.h&gt; <br>#include &lt;conio.h&gt; <br>#include &lt;alloc.h&gt; </P>
<P>void save_screen(void far *buf[4]); <br>void restore_screen(void far *buf[4]); </P>
<P>int maxx, maxy; </P>
<P>int main(void) <br>{ <br>   int gdriver=DETECT, gmode, errorcode; <br>   void far *ptr[4]; </P>
<P>   /* auto-detect the graphics driver and mode */ <br>   initgraph(&amp;gdriver, &amp;gmode, ""); <br>   errorcode = graphresult(); /* check for any errors */ <br>   if (errorcode != grOk) <br>   { <br>      printf("Graphics error: %s\n", grapherrormsg(errorcode)); <br>      printf("Press any key to halt:"); <br>      getch(); <br>      exit(1); <br>   } <br>   maxx = getmaxx(); <br>   maxy = getmaxy(); </P>
<P>   /* draw an image on the screen */ <br>   rectangle(0, 0, maxx, maxy); <br>   line(0, 0, maxx, maxy); <br>   line(0, maxy, maxx, 0); </P>
<P>   save_screen(ptr);    /* save the current screen */ <br>   getch();             /* pause screen */ <br>   cleardevice();       /* clear screen */ <br>   restore_screen(ptr); /* restore the screen */ <br>   getch();             /* pause screen */ </P>
<P>   closegraph(); <br>   return 0; <br>} </P>
<P>void save_screen(void far *buf[4]) <br>{ <br>   unsigned size; <br>   int ystart=0, yend, yincr, block; </P>
<P>   yincr = (maxy+1) / 4; <br>   yend = yincr; <br>   size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </P>
<P>   for (block=0; block&lt;=3; block++) <br>   { <br>      if ((buf[block] = farmalloc(size)) == NULL) <br>      { <br>         closegraph(); <br>         printf("Error: not enough heap space in save_screen().\n"); <br>  exit(1); <br>      } </P>
<P>      getimage(0, ystart, maxx, yend, buf[block]); <br>      ystart = yend + 1; <br>      yend += yincr + 1; <br>   } <br>} </P>
<P>void restore_screen(void far *buf[4]) <br>{ <br>   int ystart=0, yend, yincr, block; </P>
<P>   yincr = (maxy+1) / 4; <br>   yend = yincr; </P>
<P>   for (block=0; block&lt;=3; block++) <br>   { <br>      putimage(0, ystart, buf[block], COPY_PUT); <br>      farfree(buf[block]); <br>      ystart = yend + 1; <br>      yend += yincr + 1; <br>   } <br>} </P>
<P>该程序的功能:将程序所画图形均分四块利用getimage()函数保存到内存中,然后利用putimage()函数将其恢复,但是运行到第三块区域的时候,就会报错,退出图形模式输出Error: not enough heap space in save_screen().,这是何故呀?<br></P>
[align=right][color=#000066][此贴子已经被作者于2007-1-22 13:03:26编辑过][/color][/align]

一笔苍穹 发表于 2007-1-24 10:40

区域太大,存不下去了

hewenhao 发表于 2007-1-24 19:04

<P>那为什么buf[0]和buf[1]能申请得到,而buf[2]就申请失败呢?</P>

hewenhao 发表于 2007-1-24 19:31

dos中最多可以申请多大的内存空间呀?

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.