不能用于商业目的!!!
图片提取:
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
int main() {
FILE * fp1, *fp2, *fp3;
const char *dir = "F:\\新建文件夹\\";
const char *srcBmpTemplate = "C:\\Users\\Cat_Mouse\\Desktop\\template.bmp";
char srcLibName[100], desName[100];
char ctmp[10];
int data[100];
int picNum, offsetInx, offsetLoc, srcLength;
int picWidth, picHeight, picBytes, r, g, b;
int itmp, i, j, x, y, tmpoff;
strcpy(srcLibName, "C:\\Users\\Cat_Mouse\\Desktop\\Flydata.dat");
if ((fp1 = fopen(srcLibName, "rb")) == NULL) {
printf("Flydata.dat文件打开失败!\n");
return 0;
}
if ((fp2 = fopen(srcBmpTemplate, "rb")) == NULL) {
printf("template.bmp文件打开失败!\n");
return 0;
}
printf("open file ok!\n");
fseek(fp1, 0, SEEK_END);
srcLength = ftell(fp1);
fseek(fp1, 0, SEEK_SET);
fread(&picNum, 4, 1, fp1);
offsetInx = 4;
printf("picNum:%d\n", picNum);
for (i = 0; i < picNum; ++i) {
//if (i > 2) return 0;
fseek(fp1, offsetInx, 0);
fread(&offsetLoc, 4, 1, fp1);
offsetLoc += 4;
fseek(fp1, offsetLoc, 0);
printf("offsetLoc:%d\n", offsetLoc);
fread(&picWidth, 4, 1, fp1);
fread(&picHeight, 4, 1, fp1);
offsetLoc += 6;
itmp = i;
printf("w:%d h:%d\n", picWidth, picHeight);
do {
if (itmp > i)
fclose(fp3);
strcpy(desName, dir);
itoa(itmp, ctmp, 10);
strcat(desName, ctmp);
strcat(desName, ".bmp");
if ((fp3 = fopen(desName, "wb+")) == NULL) {
printf("打开文件%s失败!\n", desName);
return 0;
}
fseek(fp3, 0L, SEEK_END);
itmp++;
//printf("%ld\n", ftell(fp3));
if (ftell(fp3) > 0)
continue;
else
break;
} while (true);
fseek(fp2, 0, SEEK_SET);
fread(data, 54, 1, fp2);
fwrite(data, 54, 1, fp3);
data[0] = picWidth * picHeight * 4 + 54;
fseek(fp3, 2, 0);
fwrite(data, 4, 1, fp3);
fseek(fp3, 18, 0);
fwrite(&picWidth, 4, 1, fp3);
fseek(fp3, 22, 0);
fwrite(&picHeight, 4, 1, fp3);
picBytes = picWidth * picHeight * 2;
fseek(fp3, 0, SEEK_END);
/*itmp = 0;
for (j = 0; j <= picBytes; ++j) {
fwrite(&itmp, 1, 1, fp3);
}*/
x = 0;
y = 0;
offsetLoc += 12;
printf("%d \n", offsetLoc);
for (j = 0; j <= picBytes - 2; j += 2) {
tmpoff = offsetLoc + j;
fseek(fp1, tmpoff, 0);
fread(&itmp, 2, 1, fp1);
r = itmp & 31;
g = (itmp >> 6) & 63;
b = (itmp >> 11) & 31;
/*r *= 8;
g *= 4;
b *= 8;*/
itmp = (b << 10) | (g << 5) | r;
tmpoff = 2 * x + ( picHeight - y - 1) * (picWidth) * 2 + 54;
fseek(fp3, tmpoff, 0);
fwrite(&itmp, 2, 1, fp3);
x++;
if (x >= picWidth) {
x = 0;
y++;
}
}
fclose(fp3);
offsetInx += 4;
}
fclose(fp1);
fclose(fp2);
//system("pause");
return 0;
}
音乐提取:
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
int main() {
FILE * fp1, *fp2, *fp3;
const char *dir = "F:\\新建文件夹\\";
const char *srcSoundTemplate = "C:\\Users\\Cat_Mouse\\Desktop\\template.wav";
const int soundSize = 15;
char srcName[100], desName[100];
char ctmp[10];
int data[100];
int offsetInx, offsetLoc, wavLength;
int sndHeadBytes[2];
int itmp, i, j;
strcpy(srcName, "C:\\Users\\Cat_Mouse\\Desktop\\FlySound.lib");
if ((fp1 = fopen(srcName, "rb")) == NULL) {
printf("FlySound.lib文件打开失败!\n");
return 0;
}
if ((fp2 = fopen(srcSoundTemplate, "rb")) == NULL) {
printf("template.wav文件打开失败!\n");
return 0;
}
printf("open file ok!\n");
for (i = 0, offsetInx = 0; i < soundSize; ++i) {
fseek(fp1, offsetInx, 0);
fread(&offsetLoc, 4, 1, fp1);
fseek(fp1, offsetLoc, 0);
printf("offsetLoc:%d\n", offsetLoc);
fread(&sndHeadBytes, 4, 2, fp1);
wavLength = sndHeadBytes[0];
offsetLoc += 12;
strcpy(desName, dir);
itoa(i, ctmp, 10);
strcat(desName, ctmp);
strcat(desName, ".wav");
if ((fp3 = fopen(desName, "wb+")) == NULL) {
printf("创建文件%s失败!\n", desName);
return 0;
}
fseek(fp2, 0, SEEK_SET);
fread(data, 44, 1, fp2);
fseek(fp3, 0L, SEEK_SET);
fwrite(data, 44, 1, fp3);
fseek(fp3, 40, 0);
fwrite(&sndHeadBytes, 4, 1, fp3);
sndHeadBytes[0] = sndHeadBytes[0] + 32;
fseek(fp3, 4, 0);
fwrite(sndHeadBytes, 4, 1, fp3);
//sndHeadBytes[0] = sndHeadBytes[1];
//fseek(fp3, 20, 0);
//fwrite(&sndHeadBytes, 4, 1, fp3);
fseek(fp1, offsetLoc - 4, 0);
fseek(fp3, 0, SEEK_END);
//wavLength -= 12;
for (j = 0; j < wavLength; ++j) {
fread(&itmp, 1, 1, fp1);
fwrite(&itmp, 1, 1, fp3);
}
fclose(fp3);
offsetInx += 4;
}
fclose(fp1);
fclose(fp2);
//system("pause");
return 0;
}
本文介绍了一种从特定的数据文件中提取图片和音乐的方法。通过使用C语言编程,该过程涉及读取源数据文件,解析其中的图片和音乐信息,并将其转换为标准的.bmp和.wav格式文件。
1317

被折叠的 条评论
为什么被折叠?



