/// <summary>
        /// Update the image on a window.
        /// </summary>
        private void UpdateImage()
        {
            lock (_image)
            {
                // dispose previous image if necessary
                if (pictureBox1.Source != null)
                {
                    //pictureBox1.Source.Dispose();
                    pictureBox1.Source = null;
                }

                //
                pictureBox1.Source = _image.GetAsBitmapSource();
                //
                UpdateImageScrolls();

                //
                this.Title = string.Format("Image Processing - {0} bpp, {1}x{2}, {3}x{4} dpi",
                                           _image.ImageInfo.BitCount,
                                           _image.ImageInfo.Width,
                                           _image.ImageInfo.Height,
                                           _image.ImageInfo.Resolution.GetXResolutionInDpi(),
                                           _image.ImageInfo.Resolution.GetYResolutionInDpi());
            }
        }
        /// <summary>
        /// Sets the current image.
        /// </summary>
        private void SetCurrentImage(int index)
        {
            lock (this)
            {
                // dispose previous image if necessary
                if (image1.Source != null)
                {
                    image1.Source = null;
                }
                image1.Width  = 0;
                image1.Height = 0;


                // get the image from the internal buffer of the device if image is present
                if (index >= 0)
                {
                    AcquiredImage acquiredImage = _images[index];

                    image1.Source = acquiredImage.GetAsBitmapSource();
                    SetImageScrolls();

                    imageInfoLabel.Content = GetCurrentImageInfo(index, acquiredImage);

                    _imageIndex = index;
                }
                // show "No images" text
                else
                {
                    imageInfoLabel.Content = "No images";

                    _imageIndex = -1;
                }

                // update UI
                UpdateUI();
            }
        }