我试图在Epicor 10中构建一个自定义窗口。我添加了一个picturebox,并尝试从文件中打开图片(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 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;
}
}
}发布于 2016-02-04 19:23:39
EpiPictureBox不是从System.Windows.Forms.PictureBox派生的。它是从Infragistics.Win.UltraWinEditors.UltraPictureBox.派生的
System.Windows.Forms.PictureBox上的图像属性为System.Drawing.Image类型,其中Infragistics.Win.UltraWinEditors.UltraPictureBox的图像属性为System.Object.这就是为什么事情没有像你期望的那样行事。
我能够通过使用下面的方法获得一个模型,只要您确信分配给epiPictureBoxC1的任何东西都可以工作,那么图像就可以转换为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;
}https://stackoverflow.com/questions/35164921
复制相似问题