写了一个列出图片宽x高的 实用小程序,...
#include <stdio.h>#include <string.h>
#include <windows.h>
void getImageWidthAndHeight(const char* filename);
static unsigned int getInt(FILE* fp);
int main(void)
{
WIN32_FIND_DATA findData;
HANDLE findHadle = INVALID_HANDLE_VALUE;
char path[MAX_PATH] = "Tetris\\*.bmp"; // directory specification
findHadle = FindFirstFile(path, &findData);
if(findHadle == INVALID_HANDLE_VALUE)
{
printf("Error: invalid path\n");
}
getImageWidthAndHeight(findData.cFileName);
while(FindNextFile(findHadle, &findData) != 0)
{
getImageWidthAndHeight(findData.cFileName);
}
FindClose(findHadle);
return 0;
}
void getImageWidthAndHeight(const char* filename)
{
FILE* file;
char path[50] = {0};
char log[50] = {0};
int width, height;
sprintf(path, "Tetris\\%s", filename);
file = fopen(path, "rb");
fseek(file, 18, SEEK_CUR);
width = getInt(file);
height = getInt(file);
fclose(file);
sprintf(log, "%s: %d x %d\n", filename, width, height);
file = fopen("log.txt", "a+");
fwrite(log, sizeof(char), strlen(log), file);
fclose(file);
}
static unsigned int getInt(FILE* fp)
{
unsigned int c, c1, c2, c3;
/* get 4 bytes*/
c = getc(fp);
c1 = getc(fp);
c2 = getc(fp);
c3 = getc(fp);
return c +
(c1 << 8) +
(c2 << 16) +
(c3 << 24);
}
Exit.bmp: 145 x 97
Help.bmp: 264 x 283
MainMenu.bmp: 301 x 416
Map.bmp: 300 x 416
Pause.bmp: 141 x 46