void CTryOneDlg::OnBnClickedOpenimg()
{
// TODO: 在此添加控件通知处理程序代码
CString FileExtra;
CString FileName;
FileExtra = "BMP Files (*.bmp)|*.bmp|Dicom Files (*.dcm)|*.dcm|All Files (*.*)|*.*||";
CFileDialog dlg(true," BMP Files (*.bmp)||",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT
,FileExtra,NULL );
if( dlg.DoModal() != IDOK )
return;
FileName = dlg.GetPathName();
pImgEmbed = cvLoadImage((const char *)(LPCTSTR)FileName, CV_LOAD_IMAGE_UNCHANGED);
/*cvShowImage("win1",pImgEmbed);*/
CDC* pDC = GetDlgItem(IDC_STATIC) ->GetDC(); // 获得显示控件的 DC
HDC hDC = pDC ->GetSafeHdc(); // 获取 HDC(设备句柄) 来进行绘图操作
CRect rect;
GetDlgItem(IDC_STATIC) -> GetClientRect( &rect );
//显示图像与实际图像的长宽比
WidthScale = (double)rect.Width()/(double)(pImgEmbed -> width);
HeightScale = (double)rect.Height()/(double)(pImgEmbed -> height);
CvvImage cimg;
cimg.CopyOf(pImgEmbed); // 复制图片
cimg.DrawToHDC( hDC, &rect ); // 将图片绘制到显示控件的指定区域内
int c = rect.Height();
int d = rect.Width();
ReleaseDC( pDC );
if( m_pDicomWriter != NULL )
delete m_pDicomWriter;
m_pDicomWriter = new CTryOneDlg;
if( !m_pDicomWriter->FileRead(FileName) )
{
AfxMessageBox("文件读取失败");
delete m_pDicomWriter;
m_pDicomWriter = NULL;
return;
}
}
MFC图片加载
最新推荐文章于 2022-10-14 14:28:05 发布