以下是我编写代码以在单击 button1 后打开要在图片框上显示的文件的方式:
OpenFileDialog dlg = new OpenFileDialog();
private void button1_Click(object sender, EventArgs e)
{
dlg.Filter = "Image (*bmp)|*.bmp|All Files|*.*";
SetLogo = 0;
if (dlg.ShowDialog() == DialogResult.OK)
{
this.pictureBox1.Image = (System.Drawing.Bitmap)Image.FromFile(dlg.FileName);
int nMaxBitmapHeigth = 800;
int nMaxBitmapWidth = 950;
string strOrgFullPath = dlg.FileName;
System.Drawing.Bitmap bmpNew = new System.Drawing.Bitmap(strOrgFullPath);
System.Drawing.Bitmap bmpOrg = null;
// after this is the code for resizing the image to show on another picture box.
}
打开要在图片框中显示的图像后,我可以从combobox44中选择图像的大小:
private void comboBox44_SelectedIndexChanged(object sender, EventArgs e)
{
int nMaxBitmapHeigth = 800;
int nMaxBitmapWidth = 950;
System.Drawing.Bitmap bmpNew = new System.Drawing.Bitmap(dlg.FileName);
System.Drawing.Bitmap bmpOrg = null;
// after this is the code for resizing the image to show on another picture box.
}
button1 和combobox44 上的编码大致相同,只是button1 允许用户从对话框中选择图像文件,combobox44 将使用button1 中的图像。
但是编译后出现错误。错误指的是这一行“System.Drawing.Bitmap bmpNew = new System.Drawing.Bitmap(dlg.FileName);” 在组合框 44 上。错误消息是“路径不是合法形式”。怎么了?为什么我不能使用 button1 中的图像?