注册 登录
编程论坛 C图形专区

文件偏移怎么计算

hjj1123 发布于 2006-08-09 22:04, 1534 次点击
#include<process.h>
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
void saveall(char *filename)
{ FILE *fp;
unsigned long size=imagesize(0,0,639,120);
unsigned long save_1;
int save_i;
char *buffer;
fp=fopen(filename,"wb");
buffer=(char *)malloc(size);
for(save_i=0;save_i<4;save_i++)
{ save_1=38726L*save_i;
fseek(fp,save_1,SEEK_SET);
getimage(0,120*save_i,639,120*(save_i+1),buffer);
fwrite(buffer,size,1,fp);
}
free(buffer);
fclose(fp);
}
void loadall(char *filename)
{ FILE *fp;
unsigned long size=imagesize(0,0,639,120);
unsigned long load_1;
int load_i;
char *buffer;
if((fp=fopen(filename,"rb"))==NULL)
{ setcolor(12);
outtextxy(100,100,"<file not open !>");
fclose(fp);
return;
}
buffer=(char *)malloc(size);
for(load_i=0;load_i<4;load_i++)
{ load_1=38726L*load_i;
fseek(fp,load_1,SEEK_SET);
fread(buffer,size,1,fp);
putimage(0,120*load_i,buffer,COPY_PUT);
}
free(buffer);
fclose(fp);
}
void main()
{ int driver=DETECT,mode=0,i;
initgraph(&driver,&mode,"");
randomize();
for(i=0;i<100;i++)
{ setcolor(rand()%16);
circle(rand()%getmaxx(),rand()%getmaxy(),rand()%10);
}
saveall("screen.dat");
getch();
cleardevice();
getch();
loadall("screen,dat");
getch();
closegraph();
}
这是一个分四次显示屏幕的程序在保存和显示时都有一个文件偏移的计算save_1=38726L*save_i;和load_1=38726L*load_i; 这个38726是怎么计算出来的?帮忙解答一下.

[此贴子已经被作者于2006-8-9 22:12:56编辑过]

5 回复
#2
jig2006-08-10 09:22
这个应该是对页面的设置,这个没有道理,是硬件当初设计的时候就这样规定了,LZ记住就行。
#3
hjj11232006-08-11 17:38
这个不是对页面的设置.应该是屏幕的四分之一的数据长度,但是不知道怎么计算的.
#4
hjj11232006-08-11 17:40
还有这个程序有一个错误,连接不能通过 undefined synbol _randomize 是怎么回事?randomize是一个函数.斑竹帮忙看看,我的运行环境是WINDOWS XP TC2.0.

[此贴子已经被作者于2006-8-11 17:41:58编辑过]


#5
一笔苍穹2006-08-12 11:41
我记得randomize()要包含了stdlib.h才能用的吧
#6
hjj11232006-08-12 13:05

谢谢拉

1