void CFingerprintDlg::OnBnClickedButtonOpen()
{
// TODO: 在此添加控件通知处理程序代码
CString ImagePathName;
CFileDialog dlg(TRUE,_T("bmp"),_T(".bmp"),OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,_T("Bitmap(*.BMP)|*.BMP||"));
//设置文件对话框的对象变量
HBITMAP m_hImage;
if (dlg.DoModal()!=IDOK)
{
return; //如果对话框选择了文件
} ImagePathName=dlg.GetPathName();
//把对话框类选择的文件赋给图像文件路径变量,获取图像数据句柄
m_hImage=(HBITMAP)LoadBitmap(AfxGetInstanceHandle(),dlg.GetPathName());
//显示图像对话框
GetDlgItem(IDC_STATIC_IMAGE)->SendMessage(STM_SETIMAGE,IMAGE_BITMAP,(LPARAM)m_hImage);}
这个代码哪里不全还是什么问题?

解决方案 »

  1.   

    楼主先把路径打印出来,是否正确。
    用GetLastError看看图片加载是否成功,
    然后Invalidate试试刷新picturebox。
      

  2.   

       Bitmap^ MyImage;public:
       void ShowMyImage( String^ fileToDisplay, int xSize, int ySize )
       {      // Sets up an image object to be displayed.
          if ( MyImage != nullptr )
          {
             delete MyImage;
          }
          // Stretches the image to fit the pictureBox.
          pictureBox1->SizeMode = PictureBoxSizeMode::StretchImage;
          MyImage = gcnew Bitmap( fileToDisplay );
          pictureBox1->ClientSize = System::Drawing::Size( xSize, ySize );
          pictureBox1->Image = dynamic_cast<Image^>(MyImage);
       }