📄 subject_36957.htm
字号:
<p>
序号:36957 发表者:Jane28 发表日期:2003-04-20 12:01:22
<br>主题:急事!!!怎样将一个bmp分成127byte得块,然后再恢复成bmp?
<br>内容:bmp是不知大小,但一点小于65535byte。我自己写了一个,但是10k的只能恢复到9.29k。请问原因何在?<BR>CString m_name = "c:\\winnt\\zapotec.bmp";<BR>CFile MyFile1,MyFile2;<BR>if(!(MyFile1.Open(_T(m_name),CFile::modeRead)))<BR>{<BR> AfxMessageBox("Can't open file");<BR>}<BR>if(!(MyFile2.Open("11.bmp",CFile::modeWrite|CFile::modeCreate)))<BR>{<BR> AfxMessageBox("Can't creat file");<BR>}<BR>long Length = MyFile1.GetLength();<BR>char pData[65535];<BR>char *p;<BR>p = pData;<BR>MyFile1.Read((void *)pData,(UINT)Length);<BR>char sData[127];<BR>CString Data,rData;<BR>long i,k;<BR>for(i=0;i<Length/126;i++)<BR>{<BR> for(k=0;k<126;k++)<BR> {<BR> sData[k] = *p;<BR> p++;<BR> }<BR> Data.Format("%c",sData);<BR> rData=rData+Data;<BR>}<BR>for(i=0,k=0;i<Length%126;i++,k++)<BR>{<BR> sData[k] = *p;<BR> p++;<BR>}<BR>Data.Format("%c",sData);<BR>rData=rData+Data;<BR>MyFile2.Write((void *)rData.GetBuffer(rData.GetLength()),(UINT)Length);<BR>MyFile1.Close();<BR>MyFile2.Close();<BR>请问这个程序有什么问题?如果有更简单的,望告知!<BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:neilgan 回复日期:2003-04-20 13:35:38
<br>内容:Full of bugs.<BR><BR>1. CString is for NULL-Terminated strings. The content of .bmp file can be anything, including some NULL characters, so, you shouldn't use CString for this purpose.<BR><BR>2. Data.Format("%c",sData);<BR>What do you want to do writting this? Let me tell you what will happen in this line. CString::Format will read the first argument and find that it is required to format a char, then it goes to the second argument ,cast it to a char and put it to "Data". This line is same as:<BR>Data.Format("%c",(char)sData);<BR>or:<BR>Data.Format("%c",sData & 0xff);<BR>Surely it is not what you want.<BR><BR>you should delete all references to CString and change Data.Format(...) to: MyFile2.Write((void*)sData,k);<BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:aijun 回复日期:2003-04-20 15:03:30
<br>内容:老兄啊,如何输出一个位图,如何把位图数据还原在屏幕上啊,<BR>应该用那种数据读出位图数据?
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:Jane28 回复日期:2003-04-20 15:12:51
<br>内容:我知道也不用问你啦,我就是希望你能回答我的问题,提供一些好的方法。你说应该用什么输出格式?
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:Jane28 回复日期:2003-04-20 15:16:16
<br>内容:因为我这个是硬件的电脑程序,而硬件每一次最多只能发送127byte所以我才要拆开它来。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:aijun 回复日期:2003-04-20 15:19:09
<br>内容:有没有位图数据的专用格式啊,它不是RGB的吗,有没有像int char这种类似的啊。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:Jane28 回复日期:2003-04-20 15:31:12
<br>内容:我现在不知道。<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -