質問

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?

役に立ちましたか?

解決

I solved my programming issue again on my own. The reason why a MessageBox showed those strange messages when an image was opened via openfiledialog was the code line MessageBox::Show(sr->ReadToEnd());. Probably a part of the Image-Header was displayed in the Box. I don't need it, so the solution is to delete or to comment out this line of code.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top