int CRingTOOLDlg::ConvertSiemensPic()
{
UpdateData(TRUE);
CByteArray arrayMessage, sRing;
CString sWrite, sFileTitle, sToFile, sFileID;
sToFile.Format("%s\\siemens.pic",m_sPath);
UTIL_Base64Coder base64;
CStdioFile fFromFile, fToFile(sToFile, CFile::modeCreate | CFile::modeReadWrite);// |CFile::typeBinary);;
CFileFind cDlgFile;
char sMessage[256], sRead[8000];
int count=3500, nFileLen=0;
//头信息
char identifier[5] = {'/','/','S','E','O'};
BYTE version = 1;
short datasize;
int referenzID = 1500 ,len=0;
short actnumber = 0;
short packnumber;
char objectsize[4];
char objecttype[4] = {0x3,'b','m','p'};
char objectname[20];
char data[200];
memset(sMessage,0,sizeof(sMessage));
memset(sRead,0,sizeof(sRead));
memset(objectsize,0,4);
::SetCurrentDirectory(m_sPath);
TRY
{
if(cDlgFile.FindFile())
{
while(cDlgFile.FindNextFile())
{
CString sFile = cDlgFile.GetFileName();
if(sFile.Right(4).CompareNoCase(".bmp"))
continue;
sFileID.Format("1%d", referenzID);
len = sFile.GetLength();//sFile.GetLength();
sFileTitle = sFile.Left(sFile.GetLength()-4);
CFileException e;
if(!fFromFile.Open(sFile,CFile::modeRead | CFile::typeBinary,&e))
continue;
nFileLen = fFromFile.GetLength();
if(fFromFile.Read(sRead, nFileLen)>0)
{
memcpy(objectsize,sRead+2,2);
objectname[0] = len;
memcpy(objectname+1,sFile, len);
datasize = 140 - 25 - len;
int nSize, nLast;
memcpy(&nSize, objectsize, 4);
nLast = nSize%datasize;
if(nLast)
packnumber = nSize/datasize + 1;
else
packnumber = nSize/datasize;
actnumber = 0;
//设置头信息
memcpy(sMessage, identifier, 5);
memcpy(sMessage+5, &version, 1);
memcpy(sMessage+6, &datasize, 2);
memcpy(sMessage+8, &referenzID, 4);
memcpy(sMessage+14, &packnumber, 2);
memcpy(sMessage+16, objectsize, 4);
memcpy(sMessage+20, objecttype, 4);
memcpy(sMessage+24, objectname, len +1);
referenzID++;
for(int i=1; i<=packnumber; i++)
{
actnumber ++;
memcpy(sMessage+12, &actnumber, 2);
if(!nLast || i<packnumber)
{
memcpy(sMessage+25+len,sRead+(i-1)*datasize, datasize);
CByteArray src_array;
src_array.SetSize(140);
void *src_buffer = src_array.GetData();
memcpy(src_buffer, sMessage, 140);
base64.Encode(src_array,sRing);
}
else if(i == packnumber)
{
memcpy(sMessage+25+len,sRead+(i-1)*datasize, nLast);
CByteArray src_array;
src_array.SetSize(25+len+nLast);
void *src_buffer = src_array.GetData();
memcpy(src_buffer, sMessage, 25+len+nLast);
base64.Encode(src_array,sRing);
}
//保存到文本文件里
sWrite.Format("%d,%s,%s\r\n",count,sFileID,sRing.GetData());
fToFile.WriteString(sWrite);
}
}
fFromFile.Close();
count++;
Sleep(10);
}
AfxMessageBox("completed!");
}
}
CATCH( CFileException, e )
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e->m_cause << "\n";
#endif
}
END_CATCH
cDlgFile.Close();
return count;
}
最近写的工具中处理西门子图片的一个批量算法,比较粗糙,弄完后也没有去优化,但绝对可用。已经将需要的头包进去了,最后是按BASE64存放在文本文件里的,大家可以参考一下。