mfc中显示图像问题
在我指定的picture control显示我读取的数据因为数据的特殊性所以有这样的要求:,需要显式地
将多字节数值型字段在内存中的二进制数据字节序前后倒置,再利用memcpy函数转换成相应的真实数据类型。以下是我的代码!求高手指教为什么总是不能显示图像以及内存冲突。
void Cdemeter_csDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
CFileDialog dlg(TRUE,_T("dat"),NULL,OFN_HIDEREADONLY|OFN_FILEMUSTEXIST,_T("dat文件(*.dat)|*.dat|"),this);
CString FilePath;
if (dlg.DoModal()==IDOK)
{
FilePath=dlg.GetPathName();
}
char *p;
CBitmap bmp;
p=(char*) process1129(FilePath);
memset(&bmp,0,10240);
memcpy(&bmp,p,10240);
HDC hdc = ::GetDC(m_show1.m_hWnd);//m_show1是picture control的变量
SetStretchBltMode(hdc,HALFTONE);
StretchDIBits(hdc,0,0,260,180,0,0,250,120,p,(LPBITMAPINFO)&bmp,DIB_RGB_COLORS,SRCCOPY);
::ReleaseDC(m_show1.m_hWnd,hdc);
}
int Cdemeter_csDlg::process1129(CString FilePath)
{
CFile files;
files.Open(FilePath,CFile::modeRead);
int i;
struct block_1129 block;
for(i=0;i<256;i++){
ProcessEndian((char*)&block.block4.sample1[i],4);}
return 0;
}
void ProcessEndian(char * pHostData, int nHostDataLength)
{
char buffer[10];
int i = 0;
char *pChar = NULL;
for (i=0; i<nHostDataLength; i++)
{
pChar = pHostData+i;
buffer[i] = *(pChar);
}
for (i=0; i<nHostDataLength; i++)
{
*pChar = buffer[ i ];
pChar--;
}
}