Example #1
0
        private void ShowImage()
        {
            if ((currentIndex < 0) || (currentIndex >= elements.Count))
            {
                return;
            }

            parentListView.SelectedItem = elements[currentIndex];
            parentListView.ScrollIntoView(parentListView.SelectedItem);
            Title = elements[currentIndex].Name;

            MemoryStream ms = new MemoryStream();

            (elements[currentIndex] as FileElement).SaveTo(ms);
            image.SnapsToDevicePixels = true;
            image.UseLayoutRounding   = true;
            image.RenderTransform     = new ScaleTransform();
            Zoom = 1;
            //image.Source = img;
            //BitmapFrame bmp = null;

            bmp = null;

            try
            {
                ms.Position  = 0;
                bmp          = ImgConverter.StreamToBitmapImage(ms);
                image.Source = bmp;
                //bmp = BitmapFrame.Create(ms, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
                //ImageBehavior.SetAnimatedSource(image, bmp);
                //bmp = null;
            }
            catch
            {
            }

            ms.Dispose();

            TextBlockStatus1.Text = "Image size: " + FormatingSize(elements[currentIndex].Size);
            TextBlockStatus2.Text = "Image resolution: " + bmp?.PixelWidth + " x " + bmp?.PixelHeight;
            TextBlockStatus3.Text = "DPI: X=" + (int?)bmp?.DpiX + "  Y=" + (int?)bmp?.DpiY;
            TextBlockStatus4.Text = (currentIndex + 1).ToString() + @" / " + elements.Count.ToString();


            try
            {
                if (((bmp.Width * (bmp.DpiX / 96)) > border.RenderSize.Width) || ((bmp.Height * (bmp.DpiY / 96)) > border.RenderSize.Height) || (border.Width == 0) || (bmp.DpiX == 0) || (bmp.DpiY == 0))
                {
                    image.Stretch = Stretch.Uniform;
                }
                else
                {
                    image.Stretch         = Stretch.None;
                    image.RenderTransform = new ScaleTransform(bmp.DpiX / 96, bmp.DpiY / 96, bmp.Width / 2, bmp.Height / 2);
                }
            }
            catch
            { }

            GC.Collect();
        }