Epicor10-Image.Save 方法
Epicor10-Image.Save method
我正在尝试在 Epicor 10 中构建自定义 window。
我添加了一个图片框,然后尝试从文件中打开图片 (bmp),然后使用另一个按钮将其保存到其他地方。
问题是在 Epicor 10 的自定义工具对话框中,我在编译时编写代码时不断收到此错误:
Error: CS1061 - line 258 (953) - 'object' does not contain a definition for 'Save' and no extension method 'Save' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
** Compile Failed. **
现在,当我复制代码并使用 Visual Studio 2012 重新创建一个 windows 表单应用程序时,一切正常,编译完全没有错误。
代码很简单:
private void epiButtonC6_Click(object sender, System.EventArgs args)
{
var fd = new SaveFileDialog();
fd.Filter = "Bmp(*.Bmp)|*.bmp;| Jpg(*Jpg)|*.jpg;| Png(*Png)|*.png";
fd.AddExtension = true;
if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
switch (Path.GetExtension(fd.FileName).ToUpper())
{
case ".BMP":
epiPictureBoxC1.Image.Save(fd.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
break;
case ".JPG":
epiPictureBoxC1.Image.Save(fd.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
break;
case ".PNG":
epiPictureBoxC1.Image.Save(fd.FileName, System.Drawing.Imaging.ImageFormat.Png);
break;
default:
break;
}
}
}
EpiPictureBox 并非源自 System.Windows.Forms.PictureBox。它源自 Infragistics.Win.UltraWinEditors.UltraPictureBox。
System.Windows.Forms.PictureBox 上的图像 属性 的类型为 System.Drawing.Image,其中图像Infragistics.Win.UltraWinEditors.UltraPictureBox 的 属性 是 System.Object。这就是为什么事情不像您期望的那样表现。
我能够通过使用以下内容获得一个模型,只要您确定分配给 epiPictureBoxC1.Image 的属性的任何内容确实能够被转换为 System.Drawing.Image
switch (Path.GetExtension(fd.FileName).ToUpper())
{
case ".BMP":
((System.Drawing.Image)epiPictureBoxC1.Image).Save(fd.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
break;
case ".JPG":
((System.Drawing.Image)epiPictureBoxC1.Image).Save(fd.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
break;
case ".PNG":
((System.Drawing.Image)epiPictureBoxC1.Image).Save(fd.FileName, System.Drawing.Imaging.ImageFormat.Png);
break;
default:
break;
}
我正在尝试在 Epicor 10 中构建自定义 window。 我添加了一个图片框,然后尝试从文件中打开图片 (bmp),然后使用另一个按钮将其保存到其他地方。 问题是在 Epicor 10 的自定义工具对话框中,我在编译时编写代码时不断收到此错误:
Error: CS1061 - line 258 (953) - 'object' does not contain a definition for 'Save' and no extension method 'Save' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
** Compile Failed. **
现在,当我复制代码并使用 Visual Studio 2012 重新创建一个 windows 表单应用程序时,一切正常,编译完全没有错误。
代码很简单:
private void epiButtonC6_Click(object sender, System.EventArgs args)
{
var fd = new SaveFileDialog();
fd.Filter = "Bmp(*.Bmp)|*.bmp;| Jpg(*Jpg)|*.jpg;| Png(*Png)|*.png";
fd.AddExtension = true;
if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
switch (Path.GetExtension(fd.FileName).ToUpper())
{
case ".BMP":
epiPictureBoxC1.Image.Save(fd.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
break;
case ".JPG":
epiPictureBoxC1.Image.Save(fd.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
break;
case ".PNG":
epiPictureBoxC1.Image.Save(fd.FileName, System.Drawing.Imaging.ImageFormat.Png);
break;
default:
break;
}
}
}
EpiPictureBox 并非源自 System.Windows.Forms.PictureBox。它源自 Infragistics.Win.UltraWinEditors.UltraPictureBox。
System.Windows.Forms.PictureBox 上的图像 属性 的类型为 System.Drawing.Image,其中图像Infragistics.Win.UltraWinEditors.UltraPictureBox 的 属性 是 System.Object。这就是为什么事情不像您期望的那样表现。
我能够通过使用以下内容获得一个模型,只要您确定分配给 epiPictureBoxC1.Image 的属性的任何内容确实能够被转换为 System.Drawing.Image
switch (Path.GetExtension(fd.FileName).ToUpper())
{
case ".BMP":
((System.Drawing.Image)epiPictureBoxC1.Image).Save(fd.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
break;
case ".JPG":
((System.Drawing.Image)epiPictureBoxC1.Image).Save(fd.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
break;
case ".PNG":
((System.Drawing.Image)epiPictureBoxC1.Image).Save(fd.FileName, System.Drawing.Imaging.ImageFormat.Png);
break;
default:
break;
}