VC++ fread读取图片 并已16进制存在文本中 请给一个Demo
1个回答
展开全部
读取图片指的是读取图片里的16进制内容吗?如果是的话
#include <string>
#include <iostream>
#include <fstream>
#include <memory>
void main()
{
std::string sSourceDir,sDestinationDir;
std::cout<<"Please enter source dir:";
std::cin>>sSourceDir;
std::cout<<"Please enter destination dir:";
std::cin>>sDestinationDir;
std::ifstream ifsI(sSourceDir,std::ios::binary);
std::ofstream ofsO(sDestinationDir,std::ios::out|std::ios::trunc);
unsigned __int8 ui8Space;
char cSpace;
unsigned __int8 cBytes=0;
while (ifsI.read((char*)&ui8Space,sizeof(unsigned __int8)))
{
cSpace=ui8Space/0x10;
cSpace=cSpace>=10?cSpace+'A'-10:cSpace+'0';
ofsO<<cSpace;
cSpace=ui8Space%0x10;
cSpace=cSpace>=10?cSpace+'A'-10:cSpace+'0';
ofsO<<cSpace;
cBytes++;
if (cBytes>=16)
{
cBytes%=16;
ofsO<<std::endl;
ofsO.flush();
}
else
{
ofsO<<" ";
}
};
}
来自:求助得到的回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询