Epicor10-Image.Save method

601 Views Asked by At

I am trying to build a customized window in Epicor 10. I have added a picturebox and just try to open a picture(bmp) from a file and then with another button to save it somewhere else. The problem is that in Customization Tools Dialog from Epicor 10, where I write the code when I compile I keep getting this error:

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. **

Now, when I have copied the code, and re-created a windows form app with Visual Studio 2012, everything works just fine, no errors on compilation at all.

The code is quite simple:

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;
            }
        }       
}
1

There are 1 best solutions below

0
On BEST ANSWER

EpiPictureBox is not derived from System.Windows.Forms.PictureBox. It is derived from Infragistics.Win.UltraWinEditors.UltraPictureBox.

The Image property on System.Windows.Forms.PictureBox is of type System.Drawing.Image where as the Image property of Infragistics.Win.UltraWinEditors.UltraPictureBox is a System.Object. This is why things are not behaving as you expect them to.

I was able to get a mockup working by using the following which will work as long as you are sure that whatever is assigned to proptery of epiPictureBoxC1.Image is indeed going to be able to be cast as a 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;
        }