五月 02, 2011

Dev C++轉換不同電腦之檔頭參數

僅可使用樓下程式所轉換出之圖檔(*.xxx)設定檔頭

#include <cstdlib>
#include <iostream>
#include <dirent.h>
#include <graphics.h>

using namespace std;

int main(int argc, char *argv[])
{
unsigned char header[24];
long i,j,k,m,n,p,s,t;
long size,x=0,y=0;
int mlen;
DIR *dip;
struct dirent *dit;
FILE *fp;
void *temp;

initwindow(800,600);

x=800;
y=600;
size=imagesize(0,0,x,y);
x--;
y--;

setfillstyle(7,LIGHTBLUE);
bar(0,0,x,y);

temp = malloc(size);
getimage(0, 0, x, y, temp);

fp = fopen("temp.tmp", "wb");
fwrite(temp, sizeof(unsigned char), size, fp);
fclose(fp);
free(temp);

closegraph();

fp = fopen("temp.tmp", "rb");
fread(header, sizeof(unsigned char), 24, fp);
fclose(fp);

if((dip = opendir(".")) != false){
while((dit = readdir(dip)) != false){
mlen=strlen(dit->d_name);
if(mlen>=5){
for(i=mlen-2;i<mlen;i++){
if(dit->d_name[i]!='x')
i=999;
}
if(i<999){
cout <<dit->d_name<<" = "<<strlen(dit->d_name)<<"n";
fp = fopen(dit->d_name, "rb");
fseek(fp,0,SEEK_END);
size = ftell(fp);
fseek(fp,0, SEEK_SET);
unsigned char target[size];
fread(target, sizeof(unsigned char), size, fp);
fclose(fp);
target[22]=header[22];
target[23]=header[23];
fp = fopen(dit->d_name, "wb");
fwrite(target, sizeof(unsigned char), size, fp);
fclose(fp);
}
}
}
closedir(dip);
}

cout <<"n";
system("PAUSE");
return EXIT_SUCCESS;
}


Posted by superman at 03:05  迴響 (0)引用 (0)C語言教學

引用URL

http://blog2.cyhs.tp.edu.tw/teacher/trackback.php?id=2765
回應文章