0

In three ways I tried to display an image within a Windows Forms Picturebox using Visual C++ 2010 Express. The files path I fetch with an openFileDialog. Here are the three attempts:

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));

Before the image is displayed finally an error- or info-message pops up. The message window has no name an shows BM6 (opening a Bimap-Image), nothing (opening a JPEG-Image) or ?PNG[] (opening a PNG-Image).

Question: How I can avoid those messages when displaying an image within a picturebox?

4

1 回答 1

0

我自己又解决了我的编程问题。MessageBoxa打开图像时显示这些奇怪消息的原因openfiledialog是代码行MessageBox::Show(sr->ReadToEnd());。可能 Image-Header 的一部分显示在 Box 中。我不需要它,所以解决方法是删除或注释掉这行代码。

于 2013-11-05T12:36:03.847 回答