int main()
{
FILE * fpPhoto, *Head_w;//定义指向文件的指针
unsigned char Exif;
fopen_s(&fpPhoto,"E:\\吴老师\\wu teacher\\DJI_0001.JPG", "rb");//以只读方式打开一个二进制文件
if (!fpPhoto)
{
printf("打开文件失败!\n");
system("pause");
return -1;
}
else
{
printf("打开成功!\n");
fseek(fpPhoto, 3L, SEEK_SET);
fread(&Exif, sizeof(unsigned char), 1, fpPhoto);
printf("%x\n%d",Exif,Exif );
}
Exif = 97;
fopen_s(&Head_w, "C:\\Users\\Administrator\\Desktop\\01.txt", "w");//以只写方式打开一个文本文件,指定文件不存在,建立新文件
fwrite(&Exif, sizeof(unsigned char), 1, Head_w);
fclose(fpPhoto);
fclose(Head_w);
system("pause");
return 0;
}
void readPNGAndPrintHex(const string &originalPath,const string &targetPath)
{
FILE *pngFile,*targetFile;
fopen_s(&pngFile, originalPath.c_str(), "r");
if (pngFile == NULL)
{
printf("以r模式打开%s失败!!!", originalPath);
return;
}
fopen_s(&targetFile, targetPath.c_str(), "w+");
if (targetFile == NULL)
{
printf("以w+模式打开%s失败!!!", targetPath);
}
char buffer;
size_t size;
while (size = fread(&buffer,sizeof(char),1,pngFile))
{
char s2[256];
sprintf_s(s2, 256,"%x", buffer);
fwrite(s2, sizeof(char), 1, targetFile);
}
fclose(targetFile);
fclose(pngFile);
}