为什么恢复时我的JPEG无法恢复。 C? 不确定我做错了什么,如果你看到任何关闭,请告诉我。 我嵌入了评论以避免混淆。
typedef uint8_t BYTE;
int main(void)
{
FILE* fimg = fopen("card.raw", "r");
if (fimg == NULL)
{
fclose(fimg);
fprintf(stderr, "Image does not exist in the cardfile.\n");
return 1;
}
// counter to keep track of files found
int counter = 0;
// a buffer of 512 bytes
BYTE buffer[512];
BYTE check[4];
FILE* temp = NULL;
fread(buffer, 512, 1, fimg);
// starting bytes for the jpeg files.
BYTE chkjpg0[4] = {0xff, 0xd8, 0xff, 0xe0};
BYTE chkjpg1[4] = {0xff, 0xd8, 0xff, 0xe1};
char fname[10];
while (fread(buffer, 512, 1, fimg) > 0)
{
// check first couple of sequence of the jpg
for(int i = 0; i < 4; i++)
{
check[i] = buffer[i];
}
if (chkjpg0 == 0 || chkjpg1 == 0)
{
// label the files with three digits
sprintf(fname, "%03d.jpg", counter);
// next file in line
temp = fopen(fname, "w");
// CRANK IT UP
counter++;
// new file with buffer
fwrite(buffer, sizeof(buffer), 1, temp);
}
else if (counter > 0)
{
// put jpg into temp
fwrite(buffer, sizeof(buffer), 1, temp);
}
fread(buffer, sizeof(buffer), 1, fimg);
}
fclose(fimg);
return 0;
}