imagesize是一种
函数名,功能是返回保存位图像所需的字节数。
基本信息
用 法: unsigned far imagesize(int left, int top, int right, int bottom);
程序举例
#include
#include
#include
#define ARROW_SIZE 10
void draw_arrow(int x,int y);
int main(void)
int gdriver,gmode,errorcode;
int x,y,maxx;
int *arrow;
unsigned size;
/* initialize graphics and local variables */ //初始化图形和局部变量
gdriver=DETECT;
initgraph(&gdriver,&gmode,);
/* read the result of initialization */ //读取初始化的结果
(errorcode=graphresult);
if(errorcode!=grOk) /* an error occurred */
(getch);
exit(1); /* terminate with an error code */
(maxx=getmaxx);
x=0;
(y=getmaxy)/2;
/* calculate the size of the image */ //计算图像的大小
size=imagesize(x,y-ARROW_SIZE,x+2*ARROW_SIZE,y+ARROW_SIZE);
/* allocate memory to hold the image */ //重复直到一个键被按下
arrow=(int*)malloc(size);
/* grab the image */ //获取图像
getimage(x,y-ARROW_SIZE,x+2*ARROW_SIZE,y+ARROW_SIZE,arrow);
/* repeat until a key is pressed */
while(!kbhit())
/* plot new image */ //重新打印的图像
draw_arrow(x,y);
delay(400); /* delay time */ //延迟时间
/* erase old image */ //删除旧图片
putimage(x,y-ARROW_SIZE,arrow,AND_PUT);
x+=2*ARROW_SIZE;
if(maxx-x<2*ARROW_SIZE) x=0;
/* clean up */ //清理
free(arrow);
closegraph;
return 0;
/* draw an arrow on the screen */ //在屏幕上画一个箭头
void draw_arrow(int x,int y)
moveto(x,y);
linerel(0,-1*ARROW_SIZE);
linerel(2*ARROW_SIZE,ARROW_SIZE);
linerel(-2*ARROW_SIZE,ARROW_SIZE);
linerel(0,-1*ARROW_SIZE);