Пример #1
0
        internal void AddImage()
        {
            try
            {
                OpenFileDialog ofd = new OpenFileDialog();

                ofd.Title       = "Select an image";
                ofd.Multiselect = true;
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    Bitmap bmpStorage = new Bitmap(1, 1);

                    foreach (string Filename in ofd.FileNames)
                    {
                        try
                        {
                            //Gets file name without ext. for thumbnail list
                            System.IO.FileInfo fi = new System.IO.FileInfo(Filename);

                            m_frmMain.tlLoadedImages.AddElement((Bitmap)Image.FromFile(Filename), fi.Name);
                            bmpStorage = m_Controller.AddImage(Filename);
                        }
                        catch (Exception ex)
                        {
                            if (ex.Message == "Out of memory.")
                            {
                                bool bWasCacheEnabled = m_Controller.ForceCacheCheck();
                                if (bWasCacheEnabled)
                                {
                                    //Try again now that cache is enabled
                                    //Gets file name without ext. for thumbnail list
                                    System.IO.FileInfo fi = new System.IO.FileInfo(Filename);

                                    m_frmMain.tlLoadedImages.AddElement((Bitmap)Image.FromFile(Filename), fi.Name);
                                    bmpStorage = m_Controller.AddImage(Filename);
                                }
                                else //Something has seriously gone wrong here.
                                {
                                    throw ex;
                                }
                            }
                            else
                            {
                                throw ex;
                            }
                        }
                    }

                    bmpOutput = bmpStorage;
                    m_frmMain.tlLoadedImages.RecalculateScrollbars();
                    m_frmMain.tlLoadedImages.SetIndex(m_frmMain.tlLoadedImages.Count - 1);

                    //Set image hue and sat slider
                    m_frmMain.itHue.ReInit(uiImageTrackbar.TrackbarColorType.Hue, bmpOutput);
                    m_frmMain.itSaturation.ReInit(uiImageTrackbar.TrackbarColorType.Saturation, bmpOutput);
                }

                m_frmMain.tlImageHistory.RemoveAllElements();
            }
            catch (Exception ex)
            {
                Global.WriteToLog(ex);
            }
        }