2013-11-01 40 views
0

在三種方式中,我嘗試使用Visual C++ 2010 Express在Windows窗體圖片框中顯示圖像。我用openFileDialog獲取的文件路徑。下面是三次嘗試:最後一個無差錯或信息的消息顯示在圖像VC++在圖片框內顯示圖像會導致錯誤

1.

pictureBox1->ImageLocation = openFileDialog1->FileName; 

2.

Bitmap^ image1; 
image1 = gcnew Bitmap(openFileDialog1->FileName, true); 
pictureBox1->Image = image1; 

3.

pictureBox1->Image = static_cast<Bitmap ^>(Image::FromFile(openFileDialog1->FileName)); 

之前彈出。消息窗口沒有名稱BM6(打開Bimap-Image),nothing(打開JPEG圖像)或?PNG[](打開PNG圖像)。

問題:如何在圖片框內顯示圖片時避免這些消息?

回答

0

我自己解決了我的編程問題。當通過openfiledialog打開圖像時,MessageBox顯示這些奇怪消息的原因是代碼行MessageBox::Show(sr->ReadToEnd());。 Box中可能顯示了Image-Header的一部分。我不需要它,所以解決方案是刪除或註釋掉這行代碼。