public static int SelectFrameIndex(int framesCount)
        {
            if (framesCount == 1)
            {
                return(0);
            }
            SelectImageFrameWindow selectImageFrame = new SelectImageFrameWindow(framesCount);

            selectImageFrame.ShowDialog();
            return((int)selectImageFrame.frameSelectSlider.Value - 1);
        }
        /// <summary>
        /// Loads image from specified file.
        /// </summary>
        private BitmapSource LoadImage(string filename, ref int pageIndex)
        {
            if (_imageFileStream != null)
            {
                _imageFileStream.Dispose();
                _imageFileStream = null;
            }

            string fileExt = System.IO.Path.GetExtension(filename).ToUpper();

            switch (fileExt)
            {
            // PDF file
            case ".PDF":
                if (BarcodeGlobalSettings.IsDemoVersion)
                {
                    MessageBox.Show("Evaluation version allows to extract images only from the first page of PDF document.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                if (pageIndex == -1)
                {
                    return(SelectPdfPageWindow.SelectPdfPageImage(filename, ref pageIndex));
                }
                else
                {
                    return(SelectPdfPageWindow.GetPdfPageImage(filename, pageIndex));
                }

            // TIFF file
            case ".TIF":
            case ".TIFF":
                _imageFileStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
                TiffBitmapDecoder tiffDecoder = new TiffBitmapDecoder(_imageFileStream, BitmapCreateOptions.None, BitmapCacheOption.Default);
                if (pageIndex == -1 && tiffDecoder.Frames.Count > 1)
                {
                    pageIndex = SelectImageFrameWindow.SelectFrameIndex(tiffDecoder.Frames.Count);
                    return(tiffDecoder.Frames[pageIndex]);
                }
                return(tiffDecoder.Frames[0]);

            // image
            default:
                _imageFileStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
                BitmapImage image = new BitmapImage();
                image.BeginInit();
                image.StreamSource = _imageFileStream;
                image.CacheOption  = BitmapCacheOption.OnLoad;
                image.EndInit();
                return(image);
            }
        }