#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
//包含BMP文件的结构的声明
#include "BMP.h"
//包含BMP文件的读写操作的函数
#include "function.h"
int main()
{
int ret,reta;
char path[256],Newpath[256];
BITMAPFILEHEADER bmfh;
BITMAPINFOHEADER bmih;
BYTE *imgData;
DWORD temp;
printf("Input the path of the image(.bmp) : \n");
scanf("%s",path);
reta=checkPath(path);
if(reta==-1)
{
printf("Error: the path of the image is invalid.\n");
return -1;
}
do
{
ret=printMenu();
switch(ret)
{
case 1:
reta=readBmpFileHeader(path,&bmfh);
if(reta==-1)
{
printf("Error: can not read the File Header.\n");
break;
}
printf("Read the File Header successfully.\n");
break;
case 2:
reta=readBmpInfoHeader(path,&bmih);
if(reta==-1)
{
printf("Error: can not read the Info Header.\n");
break;
}
printf("Read the Info Header successfully.\n");
break;
case 3:
reta=readBmpInfoHeader(path,&bmih);
if(reta==-1)
{
printf("Error: can not read the Info Header.\n");
break;
}
temp=bmih.biHeight*(bmih.biWidth*bmih.biBitCount+31)/32*4;
imgData=(BYTE*)malloc(temp*sizeof(BYTE));
reta=readBmpPixelData(path,imgData);
if(reta==-1)
{
printf("Error: can not read the pixel data.\n");
free(imgData);
break;
}
printf("Read the Pixel Data successfully.\n");
break;
case 4:
reta=printBmpFileHeader(path);
if(reta==-1)
{
printf("Error: can not print the File Header.\n");
break;
}
break;
case 5:
reta=printBmpInfoHeader(path);
if(reta==-1)
{
printf("Error: can not print the Info Header.\n");
break;
}
break;
case 6:
reta=printBmpPixelData(path);
if(reta==-1)
{
printf("Error: can not print the pixel data.\n");
break;
}
break;
case 7:
printf("Input the path you want to save as:\n");
scanf("%s",Newpath);
reta=saveBmp(Newpath,path);
if(reta==-1)
{
printf("Error: can not save as the image.\n");
break;
}
printf("Save as the image successfully.\n");
break;
default:
break;
}
}while(ret!=0);
return 0;
}