也求BMP转ASCII源代码,急!!! 那位大哥能发一份给我,十分感谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 BMP转ASCII?其实就是将二进制数据进行Base64编码,很简单的。要base64编码代码的话可以给你 谢谢Semigod,能否发给小弟一份编码的代码 哦?我还以为你是其他的目的呢。转换方法很简单:BOOL CVIZip::Base64EnCode(BYTE* strSrc,UINT len,CString &strDst,CString strBase64Chars){ strDst.Empty(); if(strBase64Chars=="") strBase64Chars=m_strDefaultBase64Chars; else if(!TestBase64CharsOK(strBase64Chars)) return FALSE; int srcLen; CString strTmpSrc,tmp; unsigned char ch0=0,ch1=0,ch2=0,ch3=0; srcLen=len;//strSrc.GetLength(); if(srcLen==0) return TRUE; try { for(int i=0;i<srcLen-3;i+=3) { ch0=strSrc[i];//.GetAt(i); ch1=strSrc[i+1];//.GetAt(i+1); ch2=strSrc[i+2];//.GetAt(i+2); ch3=ch2&63; ch2=((ch2>>6)+((ch1&15)<<2))&63; ch1=((ch1>>4)+((ch0&3)<<4))&63; ch0=(ch0>>2)&63; tmp.Format("%c%c%c%c",strBase64Chars.GetAt(ch0),strBase64Chars.GetAt(ch1),strBase64Chars.GetAt(ch2),strBase64Chars.GetAt(ch3)); strDst.Append(tmp); } if(i>srcLen-3) { ch0=strSrc[i];//.GetAt(i); if(i-srcLen==-2) ch1=strSrc[i+1];//.GetAt(i+1); else ch1=0; ch2=0; ch3=0; ch2=((ch2>>6)+((ch1&15)<<2))&63; ch1=((ch1>>4)+((ch0&3)<<4))&63; ch0=(ch0>>2)&63; tmp.Format("%c%c%c=",strBase64Chars.GetAt(ch0),strBase64Chars.GetAt(ch1),((i-srcLen==-2)?strBase64Chars.GetAt(ch2):'=')); strDst.Append(tmp); } } catch(...) { return FALSE; } return TRUE;} strBase64Chars为64字符的基本字符,通常是:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/但也可以根据你自己的情况使用其他的字符编码或把编码顺序打乱。要注意的是:1——源的长度不是3的倍数时,这时会产生两个或一个补充字符,这个补充字符常用=,你也可以使用其他的字符,但一定不能是基本字符之一2——解码时使用的基本字符及其顺序必须与编码时使用的完全一样,否则会出现错误。下面的是我的解码程序,有错误,没有调试,你你要修改的是返回字符串应该也是BYTE*,而且在调用前分配了足够的空间。 BOOL CVIZip::Base64DeCode(BYTE* strSrc,UINT len,CString &strDst,CString strBase64Chars){ strDst.Empty(); if(strBase64Chars=="") strBase64Chars=m_strDefaultBase64Chars; else if(!TestBase64CharsOK(strBase64Chars)) return FALSE; int srcLen; char ch0=0,ch1=0,ch2=0,ch3=0; CString tmp; srcLen=len;//strSrc.GetLength(); if(srcLen%4!=0) return FALSE; if(srcLen==0) return TRUE; try { for(int i=0;i<srcLen-4;i+=4) { ch0=strBase64Chars.Find(strSrc[i]);//.GetAt(i)); ch1=strBase64Chars.Find(strSrc[i+1]);//.GetAt(i+1)); ch2=strBase64Chars.Find(strSrc[i+2]);//.GetAt(i+2)); ch3=strBase64Chars.Find(strSrc[i+3]);//.GetAt(i+3)); if(ch0==-1||ch1==-1||ch2==-1||ch3==-1) return FALSE; ch0=(ch0<<2)+(ch1>>4); ch1=((ch1&15)<<4)+(ch2>>2); ch2=((ch2&3)<<6)+ch3; tmp.Format("%c%c%c",ch0,ch1,ch2); strDst.Append(tmp); } ch0=strBase64Chars.Find(strSrc[i]);//.GetAt(i)); ch1=strBase64Chars.Find(strSrc[i+1]);//.GetAt(i+1)); ch2=strBase64Chars.Find(strSrc[i+2]);//.GetAt(i+2)); ch3=strBase64Chars.Find(strSrc[i+3]);//.GetAt(i+3)); if(ch0==-1||ch1==-1) return FALSE; ch0=(ch0<<2)+(ch1>>4); if(ch2!=-1) ch1=((ch1&15)<<4)+(ch2>>2); else if(strSrc[i+2]!='=') return FALSE; if(ch3!=-1) ch2=((ch2&3)<<6)+ch3; else if(strSrc[i+3]!='=') return FALSE; if(ch2==-1) tmp.Format("%c",ch0); else if(ch3=-1) tmp.Format("%c%c",ch0,ch1); else tmp.Format("%c%c%c",ch0,ch1,ch2); strDst.Append(tmp); } catch(...) { return FALSE; } return TRUE;} to: Semigod() 能把你的代码给贴出来吗?借楼主的地方.我也想学习一下!!! 用CreatePipe和ReadFile执行cmd命令并读取显示信息为何慢的要命? 多个浮动窗口排列的问题 求教CCoolBar界面布局问题 TransparentBlt的问题 MSDN中的错误!!!!!!!!!!!!! 为何可执行文件只有88k,运行时却显示占用内存3M多?如何减少内存占用?(急) VC如何调试带有输入参数的Console程序? 如何用CTableCtrl中的对话框调用父对话框中的串口控件 如何打开扩展名为.img格式的文件 高手赶快过来看!关于WriteProcessMemory() 如何得到下一天的日期? 求关于Windows Install Serviced的帮助
转换方法很简单:BOOL CVIZip::Base64EnCode(BYTE* strSrc,UINT len,CString &strDst,CString strBase64Chars)
{
strDst.Empty();
if(strBase64Chars=="")
strBase64Chars=m_strDefaultBase64Chars;
else if(!TestBase64CharsOK(strBase64Chars))
return FALSE;
int srcLen;
CString strTmpSrc,tmp;
unsigned char ch0=0,ch1=0,ch2=0,ch3=0;
srcLen=len;//strSrc.GetLength();
if(srcLen==0)
return TRUE;
try
{
for(int i=0;i<srcLen-3;i+=3)
{
ch0=strSrc[i];//.GetAt(i);
ch1=strSrc[i+1];//.GetAt(i+1);
ch2=strSrc[i+2];//.GetAt(i+2);
ch3=ch2&63;
ch2=((ch2>>6)+((ch1&15)<<2))&63;
ch1=((ch1>>4)+((ch0&3)<<4))&63;
ch0=(ch0>>2)&63;
tmp.Format("%c%c%c%c",strBase64Chars.GetAt(ch0),strBase64Chars.GetAt(ch1),strBase64Chars.GetAt(ch2),strBase64Chars.GetAt(ch3));
strDst.Append(tmp);
}
if(i>srcLen-3)
{
ch0=strSrc[i];//.GetAt(i);
if(i-srcLen==-2)
ch1=strSrc[i+1];//.GetAt(i+1);
else
ch1=0;
ch2=0;
ch3=0;
ch2=((ch2>>6)+((ch1&15)<<2))&63;
ch1=((ch1>>4)+((ch0&3)<<4))&63;
ch0=(ch0>>2)&63;
tmp.Format("%c%c%c=",strBase64Chars.GetAt(ch0),strBase64Chars.GetAt(ch1),((i-srcLen==-2)?strBase64Chars.GetAt(ch2):'='));
strDst.Append(tmp);
}
}
catch(...)
{
return FALSE;
}
return TRUE;
}
源的长度不是3的倍数时,这时会产生两个或一个补充字符,这个补充字符常用=,你也可以使用其他的字符,但一定不能是基本字符之一2——
解码时使用的基本字符及其顺序必须与编码时使用的完全一样,否则会出现错误。下面的是我的解码程序,有错误,没有调试,你你要修改的是返回字符串应该也是BYTE*,而且在调用前分配了足够的空间。
{
strDst.Empty();
if(strBase64Chars=="")
strBase64Chars=m_strDefaultBase64Chars;
else if(!TestBase64CharsOK(strBase64Chars))
return FALSE;
int srcLen;
char ch0=0,ch1=0,ch2=0,ch3=0;
CString tmp;
srcLen=len;//strSrc.GetLength();
if(srcLen%4!=0)
return FALSE;
if(srcLen==0)
return TRUE;
try
{
for(int i=0;i<srcLen-4;i+=4)
{
ch0=strBase64Chars.Find(strSrc[i]);//.GetAt(i));
ch1=strBase64Chars.Find(strSrc[i+1]);//.GetAt(i+1));
ch2=strBase64Chars.Find(strSrc[i+2]);//.GetAt(i+2));
ch3=strBase64Chars.Find(strSrc[i+3]);//.GetAt(i+3));
if(ch0==-1||ch1==-1||ch2==-1||ch3==-1)
return FALSE;
ch0=(ch0<<2)+(ch1>>4);
ch1=((ch1&15)<<4)+(ch2>>2);
ch2=((ch2&3)<<6)+ch3;
tmp.Format("%c%c%c",ch0,ch1,ch2);
strDst.Append(tmp);
}
ch0=strBase64Chars.Find(strSrc[i]);//.GetAt(i));
ch1=strBase64Chars.Find(strSrc[i+1]);//.GetAt(i+1));
ch2=strBase64Chars.Find(strSrc[i+2]);//.GetAt(i+2));
ch3=strBase64Chars.Find(strSrc[i+3]);//.GetAt(i+3));
if(ch0==-1||ch1==-1)
return FALSE;
ch0=(ch0<<2)+(ch1>>4);
if(ch2!=-1)
ch1=((ch1&15)<<4)+(ch2>>2);
else if(strSrc[i+2]!='=')
return FALSE;
if(ch3!=-1)
ch2=((ch2&3)<<6)+ch3;
else if(strSrc[i+3]!='=')
return FALSE;
if(ch2==-1)
tmp.Format("%c",ch0);
else if(ch3=-1)
tmp.Format("%c%c",ch0,ch1);
else
tmp.Format("%c%c%c",ch0,ch1,ch2);
strDst.Append(tmp);
}
catch(...)
{
return FALSE;
}
return TRUE;
}
能把你的代码给贴出来吗?
借楼主的地方.我也想学习一下!!!