I don't know what the problem is exactly. I can load small jpeg files, but when I tried loading a tga file, I get the exception. I tried resizing the image but that didn't help either.
public static System.Drawing.Image resizeImage(System.Drawing.Image imgToResize, Size size)
{
return (System.Drawing.Image)(new Bitmap(imgToResize, size));
}
private void imageToolStripMenuItem4_Click(object sender, EventArgs e)
{
if (tabControl1.TabCount == 0)
{
MessageBox.Show("Please add a form first");
return;
}
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "TGA (*.tga)|*.tga|JPEG (*.jpg)|*.jpg|BITMAP FILES (*.bmp)|*.bmp|PNG (*.png)|*.png";
openFileDialog1.FilterIndex = 1;
if (System.Windows.Forms.DialogResult.OK == openFileDialog1.ShowDialog())
{
BckImageRadioBtnGrp bimrbg=new BckImageRadioBtnGrp();
bimrbg.ShowDialog();
string result = bimrbg.getResult();
if (result != null)
{
switch (result)
{
case "Center" : (GetDesignSurface(tabControl1.SelectedTab) as System.Windows.Forms.UserControl).BackgroundImageLayout = ImageLayout.Center; break;
case "Zoom" : (GetDesignSurface(tabControl1.SelectedTab) as System.Windows.Forms.UserControl).BackgroundImageLayout = ImageLayout.Zoom; break;
case "Tile" : (GetDesignSurface(tabControl1.SelectedTab) as System.Windows.Forms.UserControl).BackgroundImageLayout = ImageLayout.Tile; break;
case "Stretch" : (GetDesignSurface(tabControl1.SelectedTab) as System.Windows.Forms.UserControl).BackgroundImageLayout = ImageLayout.Stretch; break;
case "None" : (GetDesignSurface(tabControl1.SelectedTab) as System.Windows.Forms.UserControl).BackgroundImageLayout = ImageLayout.None; break;
}
}
//getting exception here. I set a small resizing size just for testing if it works. it doesn't
System.Drawing.Image img = resizeImage(System.Drawing.Image.FromFile(openFileDialog1.FileName), new Size(100, 100));
(GetDesignSurface(tabControl1.SelectedTab) as System.Windows.Forms.UserControl).BackgroundImage = img;
}
}
}
}
So, the question is, how do I load an image?