示例#1
0
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            //Configure open file dialog box 
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.FileName = "Document"; // Default file name 
            dlg.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
                "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
                "Portable Network Graphic (*.png)|*.png"; // Filter files by extension 

            if (dlg.ShowDialog() == true)
            {
                BitmapImage img = new BitmapImage(new Uri(dlg.FileName));

                string fileName = Path.GetFileName(dlg.FileName).Split('.')[0];
                string ext = Path.GetFileName(dlg.FileName).Split('.')[1];

                OSAEImageManager imgMgr = new OSAEImageManager();

                int imgID = 0;
                byte[] byt;

                if (ext.ToLower() == "jpg" || ext.ToLower() == "jpeg")
                {
                    byt = imgMgr.getJPGFromImageControl(img);
                    imgID = imgMgr.AddImage(fileName, ext, byt);
                }
                else if (ext.ToLower() == "png")
                {
                    byt = imgMgr.getPNGFromImageControl(img);
                    imgID = imgMgr.AddImage(fileName, ext, byt);
                }
                else if (ext.ToLower() == "gif")
                {
                    byt = imgMgr.getGIFFromImageControl(img);
                    imgID = imgMgr.AddImage(fileName, ext, byt);
                }

                BindImages();
            }
        }
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            //Configure open file dialog box
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.FileName = "Document"; // Default file name
            dlg.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
                "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
                "Portable Network Graphic (*.png)|*.png"; // Filter files by extension

            if (dlg.ShowDialog() == true)
            {
                BitmapImage img = new BitmapImage(new Uri(dlg.FileName));

                string fileName = Path.GetFileName(dlg.FileName).Split('.')[0];
                string ext = Path.GetFileName(dlg.FileName).Split('.')[1];

                OSAEImageManager imgMgr = new OSAEImageManager();

                int imgID = 0;
                byte[] byt;

                if (ext.ToLower() == "jpg" || ext.ToLower() == "jpeg")
                {
                    byt = imgMgr.getJPGFromImageControl(img);
                    imgID = imgMgr.AddImage(fileName, ext, byt);
                }
                else if (ext.ToLower() == "png")
                {
                    byt = imgMgr.getPNGFromImageControl(img);
                    imgID = imgMgr.AddImage(fileName, ext, byt);
                }
                else if (ext.ToLower() == "gif")
                {
                    byt = imgMgr.getGIFFromImageControl(img);
                    imgID = imgMgr.AddImage(fileName, ext, byt);
                }

                BindImages();
            }
        }