基本信息
源码名称:MFC图片操作(PRO5_PNGDlg.cpp)
源码大小:0.02M
文件格式:.cpp
开发语言:C/C++
更新时间:2020-07-21
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 1 元 
   源码介绍


oid CPRO5_PNGDlg::DrawPicToHDC(IplImage *img, UINT ID)
{
CDC *pDC = GetDlgItem(ID)->GetDC();
HDC hDC= pDC->GetSafeHdc();
CRect rect;
GetDlgItem(ID)->GetClientRect(&rect);
CvvImage cimg;
cimg.CopyOf ( img ); // 复制图片
cimg.DrawToHDC( hDC, &rect ); // 将图片绘制到显示控件的指定区域内
ReleaseDC( pDC );
}


void CPRO5_PNGDlg::On32772()
{


CString name;

name="\\*.png";
BROWSEINFO bi;
ZeroMemory(&bi, sizeof(BROWSEINFO));
bi.hwndOwner = m_hWnd;
bi.ulFlags = BIF_RETURNONLYFSDIRS;
LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
BOOL bRet = FALSE;
TCHAR szFolder[MAX_PATH*2];
szFolder[0] = _T('\0');
if (pidl)
{
if (SHGetPathFromIDList(pidl, szFolder))
bRet = TRUE;
IMalloc *pMalloc = NULL;
if (SUCCEEDED(SHGetMalloc(&pMalloc)) && pMalloc)
{
pMalloc->Free(pidl);
pMalloc->Release();
}
}

m_FileDir = szFolder;     //选择的文件夹路径
/*
CEdit* cfolder;
cfolder = (CEdit*) GetDlgItem(IDC_PATH);
cfolder->SetWindowText(szFolder);
*/
CStatic *pStatic3 = (CStatic*)GetDlgItem(IDC_STATIC_LOCA);
pStatic3->ShowWindow(SW_HIDE);
pStatic3->ShowWindow(SW_SHOW);
pStatic3->SetWindowText(m_FileDir);




OnPaint();
TRACE("\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n");
TRACE(m_FileDir);
TRACE("\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n");

SetTimer(1,1000,NULL);

}



//void CPRO5_PNGDlg::OnEnChangePath()
//{
// // TODO:  如果该控件是 RICHEDIT 控件,它将不
// // 发送此通知,除非重写 CDialogEx::OnInitDialog()
// // 函数并调用 CRichEditCtrl().SetEventMask(),
// // 同时将 ENM_CHANGE 标志“或”运算到掩码中。
//
// // TODO:  在此添加控件通知处理程序代码
//}


//void CPRO5_PNGDlg::OnErrspacePath()
//{
// // TODO: 在此添加控件通知处理程序代码
//}


void CPRO5_PNGDlg::On32771()
{

// 设置过滤器   
    TCHAR szFilter[] = _T("图片文件(*.png)|*.png|*.jpg|*.bmp|*.gif|*.raw|*.jpeg|*.dxf|*.tiff|*.psd|所有文件(*.*)|*.*||");   
    // 构造打开文件对话框   
    CFileDialog fileDlg(TRUE, _T("txt"), NULL, 0, szFilter, this);   
    CString strFilePath; 
//const char* pic_path;
CString strFilename;

    // 显示打开文件对话框   
    if (IDOK == fileDlg.DoModal())   
    {   
        // 如果点击了文件对话框上的“打开”按钮,则将选择的文件路径显示到编辑框里   
        strFilePath = fileDlg.GetPathName();   
//SetDlgItemText(IDC_PATH, strFilePath);
CStatic *pStatic1 = (CStatic*)GetDlgItem(IDC_STATIC_LOCA);
pStatic1->ShowWindow(SW_HIDE);
pStatic1->ShowWindow(SW_SHOW);
pStatic1->SetWindowText(strFilePath);

strFilename= strFilePath.Mid(strFilePath.ReverseFind('\\') 1);
//SetDlgItemText(IDC_NAME, strFilename);
CStatic *pStatic2 = (CStatic*)GetDlgItem(IDC_STATIC_NAME);

pStatic2->ShowWindow(SW_HIDE);
pStatic2->ShowWindow(SW_SHOW);
pStatic2->SetWindowText(strFilename);



}
//strcpy(pic_path,strFilePath);
//strncpy(pic_path,(LPCTSTR)str,sizeof(strFilePath));
//pic_path = (LPSTR)(LPCTSTR)strFilePath;
const wchar_t* wstr = ( LPCTSTR )strFilePath; 
char str[600] = { 0 };                                                  //可能会在名字太过复杂时产生BUG
setlocale( LC_ALL, "chs" );
//setlocale( LC_ALL, "zh_CN.UTF-8" );
wcstombs( str, wstr, wcslen( wstr ) );
setlocale( LC_ALL, "C" );

IplImage *image=NULL; //原始图像
if (image) cvReleaseImage(&image);
image = cvLoadImage(str,1); //显示图片
DrawPicToHDC(image, IDC_PICSHOW);

cvReleaseImage(&image);


}