You should have checked for the
null
reference after the
dynamic_cast<>
. For C++/CLI, you should use
cli::safe_cast<>
. Turns out that you can get
Width
and
Height
without casting to
Bitmap^
.
Try this.
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
Bitmap^ im2 = gcnew Bitmap(pictureBox1->Image->Width, pictureBox1->Image->Height);
...
}