ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 西门子图片比较粗糙的一个算法(转)

西门子图片比较粗糙的一个算法(转)

原创 Linux操作系统 作者:jcszjswkzhou 时间:2019-04-03 14:45:05 0 删除 编辑

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.get9757.htm();
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{
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 ",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 << " ";
#endif

}
end_catch
cdlgfile.close();
return count;
}

最近写的工具中处理西门子图片的一个批量算法,比较粗糙,弄完后也没有去优化,但绝对可用。已经将需要的头包进去了,最后是按base64存放在文本文件里的,大家可以参考一下。

<-- end newscontent -->


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-125494/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2007-08-29

  • 博文量
    3488
  • 访问量
    2601698