| 
 | 
 
 
 楼主 |
发表于 2004-5-8 17:45:58
|
显示全部楼层
 
 
 
< >函数名: getimage  
功  能: 将指定区域的一个位图存到主存中  
用  法: void far getimage(int left, int top, int right, int bottom,  
     void far *bitmap);  
程序例: < >#include <graphics.h>  
#include <stdlib.h>  
#include <stdio.h>  
#include <conio.h>  
#include <alloc.h> < >void save_screen(void far *buf[4]);  
void restore_screen(void far *buf[4]); <P>int maxx, maxy; <P>int main(void)  
{  
   int gdriver=DETECT, gmode, errorcode;  
   void far *ptr[4]; <P>   /* auto-detect the graphics driver and mode */  
   initgraph(&gdriver, &gmode, "");  
   errorcode = graphresult(); /* check for any errors */  
   if (errorcode != grOk)  
   {  
      printf("Graphics error: %s\n", grapherrormsg(errorcode));  
      printf("Press any key to halt:");  
      getch();  
      exit(1);  
   }  
   maxx = getmaxx();  
   maxy = getmaxy(); <P>   /* draw an image on the screen */  
   rectangle(0, 0, maxx, maxy);  
   line(0, 0, maxx, maxy);  
   line(0, maxy, maxx, 0); <P>   save_screen(ptr);    /* save the current screen */  
   getch();             /* pause screen */  
   cleardevice();       /* clear screen */  
   restore_screen(ptr); /* restore the screen */  
   getch();             /* pause screen */ <P>   closegraph();  
   return 0;  
} <P>void save_screen(void far *buf[4])  
{  
   unsigned size;  
   int ystart=0, yend, yincr, block; <P>   yincr = (maxy+1) / 4;  
   yend = yincr;  
   size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ <P>   for (block=0; block<=3; block++)  
   {  
      if ((buf[block] = farmalloc(size)) == NULL)  
      {  
         closegraph();  
         printf("Error: not enough heap space in save_screen().\n");  
  exit(1);  
      } <P>      getimage(0, ystart, maxx, yend, buf[block]);  
      ystart = yend + 1;  
      yend += yincr + 1;  
   }  
} <P>void save_screen(void far *buf[4])  
{  
   unsigned size;  
   int ystart=0, yend, yincr, block; <P>   yincr = (maxy+1) / 4;  
   yend = yincr;  
   size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ <P>   for (block=0; block<=3; block++)  
   {  
      if ((buf[block] = farmalloc(size)) == NULL)  
      {  
         closegraph();  
         printf("Error: not enough heap space in save_screen().\n");  
  exit(1);  
      } <P>      getimage(0, ystart, maxx, yend, buf[block]);  
      ystart = yend + 1;  
      yend += yincr + 1;  
   }  
} <P>void restore_screen(void far *buf[4])  
{  
   int ystart=0, yend, yincr, block; <P>   yincr = (maxy+1) / 4;  
   yend = yincr; <P>   for (block=0; block<=3; block++)  
   {  
      putimage(0, ystart, buf[block], COPY_PUT);  
      farfree(buf[block]);  
      ystart = yend + 1;  
      yend += yincr + 1;  
   }  
}  
   
</P> |   
 
 
 
 |