Ejemplo n.º 1
0
        private void SaveImagePrintBtn_Click(object sender, RoutedEventArgs e)
        {
            SaveImagePopup.IsOpen = false;
            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.Filter       = "Bitmap files (*.bmp)|*.bmp|Jpeg files (*.jpg)|*.jpg|Tiff files (*.tif)|*.tif|PNG files (*.png)|*.png";
            dlg.AddExtension = true;
            dlg.DefaultExt   = "jpg";
            dlg.FilterIndex  = 2;
            BitmapEncoder be;
            FileStream    fs;

            if (dlg.ShowDialog() == true)//System.Windows.Forms.DialogResult.OK)
            {
                var          bsource = MainImage.Source as BitmapSource;
                BitmapSource bms     = XRayImageRenderer.GetRenderedXrayImage(bsource,
                                                                              m_SourceObject,
                                                                              m_ViewObject,
                                                                              (ShaderEffect)XrayImage_Panel.Effect,
                                                                              GetListOfEffects(),
                                                                              bsource.Width,
                                                                              bsource.Height,
                                                                              _AdornerLayerManager,
                                                                              ImagePreview.IsAnnotationShown,
                                                                              ImagePreview.IsMeasurementShown);

                string fname = dlg.FileName;
                string ext   = System.IO.Path.GetExtension(fname).ToLower();

                fs = new FileStream(fname, FileMode.Create);
                switch (ext)
                {
                case ".bmp":
                    be = new BmpBitmapEncoder();
                    be.Frames.Add(BitmapFrame.Create(bms));
                    be.Save(fs);
                    break;

                case ".jpg":
                    be = new JpegBitmapEncoder();
                    be.Frames.Add(BitmapFrame.Create(bms));
                    be.Save(fs);
                    break;

                case ".png":
                    be = new PngBitmapEncoder();
                    be.Frames.Add(BitmapFrame.Create(bms));
                    be.Save(fs);
                    break;

                case ".tif":
                    be = new TiffBitmapEncoder();
                    be.Frames.Add(BitmapFrame.Create(bms));
                    be.Save(fs);
                    break;
                }
                fs.Close();
            }
        }
Ejemplo n.º 2
0
        private BitmapSource GetRenderedXrayImage()
        {
            BitmapSource bsource = MainImage.Source as BitmapSource;

            return(XRayImageRenderer.GetRenderedXrayImage(bsource,
                                                          m_SourceObject,
                                                          m_ViewObject,
                                                          (ShaderEffect)XrayImage_Panel.Effect,
                                                          GetListOfEffects(),
                                                          PanZoom_Border.ActualWidth,
                                                          PanZoom_Border.ActualHeight,
                                                          _AdornerLayerManager,
                                                          IsAnnotationsShowing(),
                                                          IsMeasurementsShowing()));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Generate the thumbnail image and layers.
        /// </summary>
        /// <param name="source">The image source</param>
        /// <param name="effects">The effect list.</param>
        public void GenerateLayers(ImageSource source, AdornerLayerManager adoner, List <Effect> effects)
        {
            // remove all children first
            BaseEffectDockpanel.Children.Clear();
            DisplayedImage = null;

            AnnotationsLayer.Height  = source.Height;
            MeasurementsLayer.Height = source.Width;

            AnnotationsLayer.Width  = source.Width;
            MeasurementsLayer.Width = source.Width;

            // create the annotations layer
            BitmapSource  bitmapSource  = (BitmapSource)source;
            DrawingVisual drawingVisual = XRayImageRenderer.GetAnnotationDrawing(bitmapSource.Width, bitmapSource.Height, bitmapSource.Width, bitmapSource.Height, adoner, Brushes.Transparent);

            AnnotationsLayer.RemoveAllLayers();
            AnnotationsLayer.AddLayer(drawingVisual);

            // create the measurements layer
            drawingVisual = XRayImageRenderer.GetMeasurementDrawing(bitmapSource.Width, bitmapSource.Height, bitmapSource.Width, bitmapSource.Height, adoner, Brushes.Transparent);
            MeasurementsLayer.RemoveAllLayers();
            MeasurementsLayer.AddLayer(drawingVisual);

            FrameworkElement scaledElement = ImageCanvas;

            scaledElement.Height = source.Height;
            scaledElement.Width  = source.Width;

            // create a scale to size the image into the area of the window
            ScaleTransform scale = new ScaleTransform();

            scale.ScaleY = Math.Min(OuterDock.MaxHeight / scaledElement.Height, OuterDock.MaxWidth / scaledElement.Width);
            scale.ScaleX = scale.ScaleY;

            OuterDock.Height = scale.ScaleY * source.Height;
            OuterDock.Width  = scale.ScaleX * source.Width;

            OptionsOverlay.Height = OuterDock.ActualHeight;
            OptionsOverlay.Width  = OuterDock.ActualWidth;

            Panel innerPanel = BaseEffectDockpanel;

            BaseEffectDockpanel.Visibility = System.Windows.Visibility.Visible;


            foreach (Effect effect in effects)
            {
                if (effect == null)
                {
                    continue;
                }
                DockPanel panel = new DockPanel();
                panel.Visibility = Visibility.Visible;
                panel.Effect     = effect;
                innerPanel.Children.Add(panel);
                innerPanel = panel;
            }

            // add the image as the inner-most element
            Image image = new Image();

            image.Source   = source;
            DisplayedImage = image;
            innerPanel.Children.Add(DisplayedImage);

            ImageCanvas.LayoutTransform = scale;
        }