Exemplo n.º 1
0
        /// <summary>
        /// Open a whole slide image.
        /// This function can be expensive; avoid calling it unnecessarily. For example, a tile server should not call Open() on every tile request. Instead, it should maintain a cache of <see cref="OpenSlideImage"/> objects and reuse them when possible.
        /// </summary>
        /// <param name="filename">The filename to open.</param>
        /// <returns>The <see cref="OpenSlideImage"/> object.</returns>
        /// <exception cref="OpenSlideUnsupportedFormatException">The file format can not be recognized.</exception>
        /// <exception cref="OpenSlideException">The file format is recognized, but an error occurred when opening the file.</exception>
        public static OpenSlideImage Open(string filename)
        {
            // Open file using OpenSlide
            var handle = OpenSlideInterop.Open(filename);

            if (handle.IsInvalid)
            {
                throw new OpenSlideUnsupportedFormatException();
            }
            if (!ThrowHelper.TryCheckError(handle, out string errMsg))
            {
                handle.Dispose();
                throw new OpenSlideException(errMsg);
            }
            return(new OpenSlideImage(handle));
        }
Exemplo n.º 2
0
        public static OpenSlideImage Open(string filename)
        {
            FileInfo fileInfo = new FileInfo(filename);
            // Open file using OpenSlide
            IntPtr handle = Interop.Open(filename);

            if (handle == IntPtr.Zero)
            {
                throw new OpenSlideUnsupportedFormatException();
            }
            if (!ThrowHelper.TryCheckError(handle, out string errMsg))
            {
                Interop.Close(handle);
                throw new OpenSlideException(errMsg);
            }
            return(new OpenSlideImage(handle, fileInfo));
        }