Esempio n. 1
0
        /// <summary>
        /// Get the image stored at the specified path as an IPicture.
        /// The PictureHolder remains responsible to dispose or release the picture as needed,
        /// typically when the application exits, so the client may keep and use it indefinitely.
        /// </summary>
        public IPicture GetComPicture(string imagePath)
        {
            IPicture comPicture;

            if (m_previousPictures == null)
            {
                m_previousPictures = new Dictionary <string, IPicture>();
            }
            if (m_previousPictures.TryGetValue(imagePath, out comPicture))
            {
                return(comPicture);
            }
            try
            {
                string actualFilePath = FileUtils.ActualFilePath(imagePath);
                using (var image = Image.FromFile(actualFilePath))
                {
                    comPicture = (IPicture)OLECvt.ToOLE_IPictureDisp(image);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Failed to create picture from path " + imagePath + " exception: " + e.Message);
                comPicture = null;                 // if we can't get the picture too bad.
            }
            m_previousPictures[imagePath] = comPicture;
            return(comPicture);
        }
Esempio n. 2
0
        /// <summary>
        /// Get an IPicture corresponding to the specified key. If one is not known,
        /// obtain it from the source image, and save it for next time. The PictureHolder
        /// remains responsible for disposing or releasing the picture in either case.
        /// </summary>
        public IPicture GetPicture(string key, Image source)
        {
            IPicture comPicture;

            if (m_previousPictures == null)
            {
                m_previousPictures = new Dictionary <string, IPicture>();
            }
            if (!m_previousPictures.TryGetValue(key, out comPicture))
            {
                comPicture = (IPicture)OLECvt.ToOLE_IPictureDisp(source);
                m_previousPictures[key] = comPicture;
            }
            return(comPicture);
        }