/// <summary> /// Renders the Xray image on the CPU. /// </summary> /// <param name="bsource"></param> /// <param name="sourceObject"></param> /// <param name="viewObject"></param> /// <param name="xrayImageEffect"></param> /// <param name="trimatEffect"></param> /// <param name="effects"></param> /// <param name="displayWidth"></param> /// <param name="displayHeight"></param> /// <param name="adornerLayerManager"></param> /// <param name="displayAnnotations"></param> /// <param name="displayMeasurements"></param> /// <returns>The newly rendered bitmap.</returns> public static BitmapSource GetRenderedXrayImage(BitmapSource bsource, SourceObject sourceObject, ViewObject viewObject, ShaderEffect xrayOrTrimateImageEffect, List<Effect> effects, double displayWidth, double displayHeight, AdornerLayerManager adornerLayerManager, bool displayAnnotations, bool displayMeasurements) { if (xrayOrTrimateImageEffect != null && xrayOrTrimateImageEffect.GetType() == typeof(XrayImageEffect)) { RenderXrayImage_XRayImageEffect(ref bsource, (XrayImageEffect)xrayOrTrimateImageEffect, sourceObject); } //else if (xrayOrTrimateImageEffect.GetType() == typeof(TrimatEffect)) //{ // RenderXrayImage_TrimatEffect(ref bsource, (TrimatEffect)xrayOrTrimateImageEffect, sourceObject, viewObject); //} foreach (Effect effect in effects) { ApplyEffectToBitmap(ref bsource, effect); } if (displayAnnotations) { RenderAnnotations(ref bsource, displayWidth, displayHeight, adornerLayerManager); } if (displayMeasurements) { RenderMeasurements(ref bsource, displayWidth, displayHeight, adornerLayerManager); } return bsource; }
public FrameWork(EventLoggerAccess logger) { try { InitializeComponent(); CultureResources.registerDataProvider(this); _Logger = logger; _StatusInfoDisplay = new StatusInfoDisplay(logger); _StatusAdorner = new AdornerContentPresenter(DisplayArea, _StatusInfoDisplay); _AboutBox = new AboutBox(); _AboutAdorner = new AdornerContentPresenter(DisplayArea, _AboutBox); _AdornerLayerManager = new AdornerLayerManager(AdornerLayer.GetAdornerLayer(DisplayArea)); _WidgetPages = new List<WidgetPage>(); } catch { } }
public XRayView () { InitializeComponent(); CultureResources.registerDataProvider(this); CultureResources.getDataProvider().DataChanged += new EventHandler(CultureResources_DataChanged); PseudoColorPath = AppDomain.CurrentDomain.BaseDirectory + "Plugins\\PseudoColor\\"; _AdornerLayerManager = new AdornerLayerManager(AdornerLayer.GetAdornerLayer(PanAndZoomControl)); _XrayImageEffect = new XrayImageEffect(); XrayImage_Panel.Effect = _XrayImageEffect; }
/// <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; }
/// <summary> /// Renders the measures on top of the source image passed in. /// </summary> /// <param name="bsource">The bsource to render to. The passed in source will be modified.</param> /// <param name="displayWidth">The width of the container to put the bitmap. Scales the size of the drawings.</param> /// <param name="displayHeight">The height of the container to put the bitmap. Scales the size of the drawings.</param> /// <param name="adonerImageObject">The adorner information object.</param> public static void RenderMeasurements(ref BitmapSource bsource, double displayWidth, double displayHeight, AdornerLayerManager adonerImageObject) { DrawingVisual dw = GetMeasurementDrawing(bsource.Width, bsource.Height, displayWidth, displayHeight, adonerImageObject, new ImageBrush(bsource)); bsource = new RenderTargetBitmap((int)bsource.Width, (int)bsource.Height, 96, 96, PixelFormats.Default); ((RenderTargetBitmap)bsource).Render(dw); }
/// <summary> /// Generates the drawing of the measurements. /// </summary> /// <param name="sourceWidth">The width of the source image.</param> /// <param name="sourceHeight">The height of the source image.</param> /// <param name="displayWidth">The width of the container to put the bitmap. Scales the size of the drawings.</param> /// <param name="displayHeight">The height of the container to put the bitmap. Scales the size of the drawings.</param> /// <param name="adornerLayerManager">The adorner information object.</param> /// <param name="background">The background to create the drawing on.</param> public static DrawingVisual GetMeasurementDrawing(double sourceWidth, double sourceHeight, double displayWidth, double displayHeight, AdornerLayerManager adornerLayerManager, Brush background) { DrawingVisual dw = new DrawingVisual(); using (DrawingContext dc = dw.RenderOpen()) { Size sz = new Size((int)sourceWidth, (int)sourceHeight); Pen p = new Pen(); Point pt = new Point(1, 1); dc.DrawRectangle(background, p, new System.Windows.Rect(pt, sz)); double widthRatio = sourceWidth / displayWidth; double heightRatio = sourceHeight / displayHeight; double Ratio = (widthRatio < heightRatio) ? widthRatio : heightRatio; MeasureAdorner measAdorner = (MeasureAdorner)adornerLayerManager.GetAdorner(AdornerLayerManager.MEASUREMENT_ADORNER); foreach (MeasurementLine lineObj in measAdorner.GetMeasurementLines()) { SolidColorBrush lscb = Brushes.Green; Pen lp1 = new Pen(lscb, 5d * Ratio); dc.DrawLine(lp1, lineObj.StartPoint, lineObj.EndPoint); float lineLength = (lineObj.Length * measAdorner.SamplingSpace) / 1000; FormattedText formattedText = new FormattedText(lineLength.ToString("F") + "m", CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface("Veranda"), 32, Brushes.Green); //formattedText.MaxTextWidth = 300; //formattedText.MaxTextHeight = 240; //formattedText.SetFontSize(32 * (96.0 / 72.0)); PrintDialog tempPrnDialog = new PrintDialog(); if (sourceWidth > sourceHeight) { formattedText.SetFontSize((sourceWidth / tempPrnDialog.PrintableAreaWidth) * 12); } else formattedText.SetFontSize((sourceHeight / tempPrnDialog.PrintableAreaHeight) * 15); Point textMidPoint = new Point(lineObj.MidPoint.X - (formattedText.Width / 2), lineObj.MidPoint.Y - (formattedText.Height / 2)); Rect LegendRect; LegendRect = new Rect(textMidPoint, new Size(formattedText.Width, formattedText.Height)); SolidColorBrush scb = Brushes.Green; Pen p1 = new Pen(scb, (5D * Ratio)); RectangleGeometry rg = new RectangleGeometry(LegendRect, 0, 0); dc.DrawGeometry(Brushes.White, null, rg); dc.DrawText(formattedText, textMidPoint); } } return dw; }
/// <summary> /// Generates the drawing of the annotations. /// </summary> /// <param name="sourceWidth">The width of the source image.</param> /// <param name="sourceHeight">The height of the source image.</param> /// <param name="displayWidth">The width of the container to put the bitmap. Scales the size of the drawings.</param> /// <param name="displayHeight">The height of the container to put the bitmap. Scales the size of the drawings.</param> /// <param name="adornerLayerManager">The adorner information object.</param> /// <param name="background">The background to create the drawing on.</param> public static DrawingVisual GetAnnotationDrawing(double sourceWidth, double sourceHeight, double displayWidth, double displayHeight, AdornerLayerManager adornerLayerManager, Brush background) { DrawingVisual dw = new DrawingVisual(); using (DrawingContext dc = dw.RenderOpen()) { Size sz = new Size((int)sourceWidth, (int)sourceHeight); Pen p = new Pen(); Point pt = new Point(1, 1); dc.DrawRectangle(background, p, new System.Windows.Rect(pt, sz)); double widthRatio = sourceWidth / displayWidth; double heightRatio = sourceHeight / displayHeight; double Ratio = (widthRatio < heightRatio) ? widthRatio : heightRatio; char[] letters = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' }; int count = 0; AnnotationAdorner annotAdorner = (AnnotationAdorner)adornerLayerManager.GetAdorner(AdornerLayerManager.ANNOTATION_ADORNER); foreach (Annotation annotation in annotAdorner.GetAnnotations()) { Rect rect = annotation.Marking.Rect; RectangleGeometry rg = new RectangleGeometry(rect, annotation.Marking.RadiusX, annotation.Marking.RadiusY); //rg. SolidColorBrush scb = Brushes.Green; Pen p1 = new Pen(scb, (5D * Ratio)); dc.DrawGeometry(null, p1, rg); string index = string.Empty; int div = (count / 26) - 1; int rem = count % 26; if (div >= 0) { index += letters[div]; } index += letters[rem]; FormattedText formattedText = new FormattedText(index, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface("Aharoni"), 32, Brushes.Green); //formattedText.MaxTextWidth = 300; //formattedText.SetFontSize(32 * (96.0 / 72.0)); PrintDialog tempPrnDialog = new PrintDialog(); if (sourceWidth > sourceHeight) { formattedText.SetFontSize((sourceWidth / tempPrnDialog.PrintableAreaWidth) * 11); } else formattedText.SetFontSize((sourceHeight / tempPrnDialog.PrintableAreaHeight) * 13); Rect LegendRect; if (annotation.Marking.RadiusX > 0) LegendRect = new Rect(annotation.Marking.Rect.TopLeft.X + (annotation.Marking.Rect.Width / 2) - ((formattedText.WidthIncludingTrailingWhitespace + 10) / 2), annotation.Marking.Rect.TopLeft.Y - formattedText.Height - 5, formattedText.WidthIncludingTrailingWhitespace + 12, formattedText.Height + 5); else LegendRect = new Rect(annotation.Marking.Rect.TopLeft.X, annotation.Marking.Rect.TopLeft.Y - formattedText.Height - 5, formattedText.WidthIncludingTrailingWhitespace + 12, formattedText.Height + 5); rg = new RectangleGeometry(LegendRect, 0, 0); dc.DrawGeometry(Brushes.LightYellow, p1, rg); dc.DrawText(formattedText, new Point(LegendRect.TopLeft.X + 5, LegendRect.TopLeft.Y + 5)); count++; } } return dw; }