当前位置: 首页>>代码示例>>C#>>正文


C# GeometryGroup.Freeze方法代码示例

本文整理汇总了C#中System.Windows.Media.GeometryGroup.Freeze方法的典型用法代码示例。如果您正苦于以下问题:C# GeometryGroup.Freeze方法的具体用法?C# GeometryGroup.Freeze怎么用?C# GeometryGroup.Freeze使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Media.GeometryGroup的用法示例。


在下文中一共展示了GeometryGroup.Freeze方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateDescriptionWaveForm

        /// <summary>
        /// Creates a waveform image from a description's audio file. Uses the description.Waveform
        /// property to obtain the data for the waveform.
        /// </summary>
        /// <param name="description">Description to create waveform for.</param>
        /// <param name="bounds">Size of the image to create.</param>
        /// <param name="canvasWidth">The width of the canvas that will contain this image.</param>
        /// <returns>A bitmap of the description's waveform.</returns>
        public static RenderTargetBitmap CreateDescriptionWaveForm(Description description, Rect bounds,
            double canvasWidth)
        {
            if (bounds.Width <= 1 || bounds.Height <= 1)
                return null;

            if (description.Waveform == null)
                description.GenerateWaveForm();

            var drawingVisual = new DrawingVisual();

            using (var dc = drawingVisual.RenderOpen())
            {
                var data = description.Waveform.Data;

                double samplesPerPixel = Math.Max(data.Count / canvasWidth, 1);
                double middle = bounds.Height / 2;
                double yscale = middle;

                double samplesPerSecond = (description.Waveform.Header.SampleRate *
                    (description.Waveform.Header.BlockAlign / (double)description.Waveform.SampleRatio));

                var waveformLineGroup = new GeometryGroup();

                int endPixel = (int)bounds.Width;

                for (int pixel = 0; pixel <= endPixel; pixel++)
                {
                    double offsetTime = (description.Duration / (bounds.Width * Milliseconds.PerSecond))
                        * pixel;
                    double sampleStart = Math.Max(samplesPerSecond * offsetTime, 0);

                    if (sampleStart + samplesPerPixel < data.Count)
                    {
                        var range = data.GetRange((int)sampleStart, (int)samplesPerPixel);

                        double max = (double)range.Max() / short.MaxValue;
                        double min = (double)range.Min() / short.MaxValue;

                        waveformLineGroup.Children.Add(new LineGeometry
                        {
                            StartPoint = new Point(pixel, middle + max * yscale),
                            EndPoint = new Point(pixel, middle + min * yscale),
                        });
                    }
                }

                waveformLineGroup.Freeze();
                dc.DrawGeometry(Brushes.Black, LinePen, waveformLineGroup);
            }

            var bitmap = new RenderTargetBitmap((int)bounds.Width, (int)bounds.Height, DefaultDpi,
                DefaultDpi, PixelFormats.Pbgra32);
            bitmap.Render(drawingVisual);
            bitmap.Freeze();

            description.WaveformImage = bitmap;

            return bitmap;
        }
开发者ID:vserrago,项目名称:LiveDescribe-Desktop,代码行数:68,代码来源:RenderTargetBitmapFactory.cs

示例2: VisualizeVectors

        private static UIElement VisualizeVectors(Point[] points, Vector[] vectors, double[] radii)
        {
            Contract.Requires(points.Length == vectors.Length);
            var n = points.Length;

            var geometryGroup = new GeometryGroup
            {
                Children = new GeometryCollection(
                    from i in Enumerable.Range(0, n)
                    let pc = points[i]
                    let pleft = pc - radii[i] * vectors[i]
                    let pright = pc + radii[i] * vectors[i]
                    from p in new Point[] { pleft, pright }
                    select new LineGeometry { StartPoint = pc, EndPoint = p }
                ),
            };
            geometryGroup.Freeze();

            return new Path { Data = geometryGroup, Stroke = Brushes.Blue, StrokeThickness = 1, };
        }
开发者ID:alexshtf,项目名称:Various-utility-projects,代码行数:20,代码来源:MainWindow.xaml.cs

示例3: VisualizeMatch

        private static UIElement VisualizeMatch(Point[] left, Point[] right)
        {
            Contract.Requires(left.Length == right.Length);
            int n = left.Length;

            var geometry = new GeometryGroup();
            for (int i = 0; i < n; ++i)
            {
                var l = left[i];
                var r = right[i];
                geometry.Children.Add(new EllipseGeometry(l, 2, 2));
                geometry.Children.Add(new EllipseGeometry(r, 2, 2));
                geometry.Children.Add(new LineGeometry(l, r));
            }
            geometry.Freeze();

            return new Path
            {
                Stroke = Brushes.Blue,
                Fill = new SolidColorBrush { Color = Colors.Blue, Opacity = 0.2 },
                Data = geometry,
            };
        }
开发者ID:alexshtf,项目名称:Various-utility-projects,代码行数:23,代码来源:MainWindow.xaml.cs

示例4: DrawBackgound

        /// <summary>
        /// Draw the hatches and the transparent area where isn't covering the elements.
        /// </summary>
        /// <param name="drawingContext"></param>
        private void DrawBackgound(DrawingContext drawingContext)
        {
            PathGeometry hatchGeometry = null;
            Geometry rectGeometry = null;

            int count = _elementsBounds.Count;
            if ( count != 0 )
            {
                // Create a union collection of the element regions.
                for ( int i = 0; i < count; i++ )
                {
                    Rect hatchRect = _elementsBounds[i];

                    if ( hatchRect.IsEmpty )
                    {
                        continue;
                    }

                    hatchRect.Inflate(HatchBorderMargin / 2, HatchBorderMargin / 2);

                    if ( hatchGeometry == null )
                    {
                        PathFigure path = new PathFigure();
                        path.StartPoint = new Point(hatchRect.Left, hatchRect.Top);

                        PathSegmentCollection segments = new PathSegmentCollection();
                        
                        PathSegment line = new LineSegment(new Point(hatchRect.Right, hatchRect.Top), true); 
                        line.Freeze();
                        segments.Add(line);
                        
                        line = new LineSegment(new Point(hatchRect.Right, hatchRect.Bottom), true); 
                        line.Freeze();
                        segments.Add(line);

                        line = new LineSegment(new Point(hatchRect.Left, hatchRect.Bottom), true);
                        line.Freeze();
                        segments.Add(line);

                        line = new LineSegment(new Point(hatchRect.Left, hatchRect.Top), true);
                        line.Freeze();
                        segments.Add(line);

                        segments.Freeze();
                        path.Segments = segments;

                        path.IsClosed = true;
                        path.Freeze();

                        hatchGeometry = new PathGeometry();
                        hatchGeometry.Figures.Add(path);
                    }
                    else
                    {
                        rectGeometry = new RectangleGeometry(hatchRect);
                        rectGeometry.Freeze();

                        hatchGeometry = Geometry.Combine(hatchGeometry, rectGeometry, GeometryCombineMode.Union, null);
                    }
                }
            }

            // Then, create a region which equals to "SelectionFrame - element1 bounds - element2 bounds - ..."
            GeometryGroup backgroundGeometry = new GeometryGroup( );
            GeometryCollection geometryCollection = new GeometryCollection();

            // Add the entile rectanlge to the group.
            rectGeometry = new RectangleGeometry(new Rect(0, 0, RenderSize.Width, RenderSize.Height));
            rectGeometry.Freeze();
            geometryCollection.Add(rectGeometry);

            // Add the union of the element rectangles. Then the group will do oddeven operation.
            Geometry outlineGeometry = null;

            if ( hatchGeometry != null )
            {
                hatchGeometry.Freeze();

                outlineGeometry = hatchGeometry.GetOutlinedPathGeometry();
                outlineGeometry.Freeze();
                if ( count == 1 && ((InkCanvasInnerCanvas)AdornedElement).InkCanvas.GetSelectedStrokes().Count == 0 )
                {
                    geometryCollection.Add(outlineGeometry);
                }
            }

            geometryCollection.Freeze();
            backgroundGeometry.Children = geometryCollection;
            backgroundGeometry.Freeze();

            // Then, draw the region which may contain holes so that the elements cannot be covered.
            // After that, the underneath elements can receive the messages.
#if DEBUG_OUTPUT
            // Draw the debug feedback
            drawingContext.DrawGeometry(new SolidColorBrush(Color.FromArgb(128, 255, 255, 0)), null, backgroundGeometry);
#else
//.........这里部分代码省略.........
开发者ID:JianwenSun,项目名称:cc,代码行数:101,代码来源:InkCanvasSelectionAdorner.cs

示例5: CreateDotChartGeometry

        public void CreateDotChartGeometry(ICollection dt, double _maxData, double chartHeight, double chartWidth)
        {
            _children.Clear();
            stopWatch.Restart();

            var barWidth = SetBarWidth(dt.Count, chartWidth);
            var ellipses = new GeometryGroup();

            // For each row in the datasource
            double centerX = _axis_start;
            foreach (var el in dt)
            {
                // Calculate bar value.
                var height = Convert.ToDouble(el) * (chartHeight - _axis_start) / _maxData;
                centerX += barWidth;
                ellipses.Children.Add(
                    new EllipseGeometry(new Point(centerX, chartHeight - height - _axis_start), 1, 1)
                    );
            }
            ellipses.Freeze();

            var visual = new DrawingVisual();
            using (var dc = visual.RenderOpen())
            {
                dc.DrawGeometry(null, _chartPen, ellipses);
                stopWatch.Stop();

                var elapsedTime = String.Format("{0} - {1} - {2}", MethodBase.GetCurrentMethod().Name, dt.Count, stopWatch.ElapsedTicks);

                dc.DrawText(
                    new FormattedText(elapsedTime, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, new Typeface("Verdana"),
                                      12, Brushes.LightGreen), new Point(10, 10));

            }
            _children.Add(visual);
        }
开发者ID:havok,项目名称:ngenerics,代码行数:36,代码来源:MyVisualHost.xaml.cs

示例6: DrawWaveForm

        /// <summary>
        /// Draws the waveform for the current window of sound and adds it to the AudioCanvas.
        /// </summary>
        public void DrawWaveForm()
        {
            if (_viewModel == null || _viewModel.Waveform == null || Width == 0 || VisibleWidth == 0
                || _viewModel.Player.CurrentState == LiveDescribeVideoStates.VideoNotLoaded)
            {
                ResetImageOnCanvas(_waveformImage);
                return;
            }

            var data = _viewModel.Waveform.Data;
            double samplesPerPixel = Math.Max(data.Count / Width, 1);
            double middle = ActualHeight / 2;
            double yscale = middle;

            int ratio = _viewModel.Waveform.Header.Channels == 2 ? 40 : 80;
            double samplesPerSecond =
                (_viewModel.Waveform.Header.SampleRate * (_viewModel.Waveform.Header.BlockAlign / (double)ratio));

            var waveformLineGroup = new GeometryGroup();

            double absMin = 0;

            int endPixel = (int)VisibleX + (int)VisibleWidth;

            for (int pixel = (int)VisibleX; pixel <= endPixel; pixel++)
            {
                double offsetTime = (VideoDurationMsec / (Width * Milliseconds.PerSecond))
                    * pixel;
                double sampleStart = samplesPerSecond * offsetTime;

                if (sampleStart + samplesPerPixel < data.Count)
                {
                    var range = data.GetRange((int)sampleStart, (int)samplesPerPixel);

                    double max = (double)range.Max() / short.MaxValue;
                    double min = (double)range.Min() / short.MaxValue;

                    waveformLineGroup.Children.Add(new LineGeometry
                    {
                        StartPoint = new Point(pixel, middle + max * yscale),
                        EndPoint = new Point(pixel, middle + min * yscale),
                    });

                    absMin = Math.Min(absMin, min);
                }
            }

            waveformLineGroup.Freeze();

            var dv = new DrawingVisual();
            using (var drawingContext = dv.RenderOpen())
            {
                drawingContext.DrawGeometry(Brushes.Black, LinePen, waveformLineGroup);
            }

            DisplayVisualOnCanvas(_waveformImage, dv, middle + absMin * yscale);
        }
开发者ID:vserrago,项目名称:LiveDescribe-Desktop,代码行数:60,代码来源:AudioCanvas.cs

示例7: MarkersAsGeometry

 internal static Geometry MarkersAsGeometry(Curve curve, MatrixTransform graphToCanvas, MarkersType markersType, double markersSize)
 {
     double xScale = graphToCanvas.Matrix.M11;
     double xOffset = graphToCanvas.Matrix.OffsetX;
     double yScale = graphToCanvas.Matrix.M22;
     double yOffset = graphToCanvas.Matrix.OffsetY;
     GeometryGroup markers = new GeometryGroup();
     double width = Math.Abs(markersSize);
     double height = Math.Abs(markersSize);
     Geometry markerGeometry = LegendMarkerGeometry(markersType, markersSize);
     if (markerGeometry == null) return null;
     markerGeometry.Freeze();
     for (int i = 0; i < curve.xTransformed.Length; ++i)
     {
         if (!curve.includeMarker[i]) continue;
         double xCanvas = curve.xTransformed[i] * xScale + xOffset;
         double yCanvas = curve.yTransformed[i] * yScale + yOffset;
         Geometry newMarker = markerGeometry.Clone();
         newMarker.Transform = new TranslateTransform(xCanvas, yCanvas);
         markers.Children.Add(newMarker);
     }
     markers.Freeze();
     return markers;
 }
开发者ID:goutkannan,项目名称:ironlab,代码行数:24,代码来源:MarkerGeometries.cs

示例8: VisualizePoints

        private UIElement VisualizePoints(Point[] point)
        {
            var path = new Path();
            path.Stroke = Brushes.Blue;
            path.StrokeThickness = 1;
            path.Fill = new SolidColorBrush { Color = Colors.Blue, Opacity = 0.2 };

            var geometry = new GeometryGroup();
            foreach (var pnt in point.Skip(1).Take(point.Length - 2))
                geometry.Children.Add(new EllipseGeometry(pnt, 2, 2));

            geometry.Children.Add(new EllipseGeometry(point[0], 5, 5));
            geometry.Children.Add(new EllipseGeometry(point[point.Length - 1], 5, 5));

            geometry.Freeze();
            path.Data = geometry;

            return path;
        }
开发者ID:alexshtf,项目名称:Various-utility-projects,代码行数:19,代码来源:MainWindow.xaml.cs

示例9: renderColumns

        private void renderColumns(List<int> columns, Brush brush, Image image)
        {
            GeometryGroup group = new GeometryGroup();
            group.Children.Add(new RectangleGeometry(new Rect(0, 0, 0, 0)));
            renderColumnsForLines(group, columns, _view.TextViewLines);
            group.Freeze();

            Drawing drawing = new GeometryDrawing(brush, _emptyPen, group);
            drawing.Freeze();

            DrawingImage drawingImage = new DrawingImage(drawing);
            drawingImage.Freeze();

            image.Source = drawingImage;

            Canvas.SetLeft(image, _view.ViewportLeft + group.Bounds.Left);
            Canvas.SetTop(image, _view.ViewportTop + group.Bounds.Top);
        }
开发者ID:fpicalausa,项目名称:Color-Column,代码行数:18,代码来源:ColorColumn.cs

示例10: Show


//.........这里部分代码省略.........
                            height = h;
                        }
                    }

                    if (height > 0)
                    {
                        height -= 11;
                    }

                    if (size1.Width > maxSize.Width)
                    {
                        maxSize.Width = size1.Width;
                    }

                    if (size1.Height + height > maxSize.Height)
                    {
                        maxSize.Height = size1.Height + height;
                    }
                }

                maxSize.Width = maxSize.Width * this.maxScale;
                maxSize.Height = maxSize.Height * this.maxScale;
            }

            this.sourceSize = this.targetSize = balloonSize;
            this.targetOpacity = 1;
            this.targetScaleX = this.targetScaleY = 1;

            Geometry roundedRectangleGeometry = CreateRoundedRectangleGeometry(new Rect(0, 0, this.sourceSize.Width, this.sourceSize.Height - 11 + 4), 8, 8);
            Geometry balloonGeometry = CreateBalloonGeometry(new Rect(4, 4, this.sourceSize.Width - 4 * 2, this.sourceSize.Height - 4), 8 * 3 / 4, 8 * 3 / 4);
            Geometry highlightGeometry = CreateHighlightGeometry(new Rect(0, 0, this.sourceSize.Width, this.baseHeaderHeight + 8), 8, 8);
            Geometry highlightLineGeometry = CreateHighlightLineGeometry(new Rect(0, 0, this.sourceSize.Width, 8), 8, 8);

            if (roundedRectangleGeometry.CanFreeze)
            {
                roundedRectangleGeometry.Freeze();
            }

            if (balloonGeometry.CanFreeze)
            {
                balloonGeometry.Freeze();
            }

            if (highlightGeometry.CanFreeze)
            {
                highlightGeometry.Freeze();
            }

            if (highlightLineGeometry.CanFreeze)
            {
                highlightLineGeometry.Freeze();
            }

            GeometryGroup geometryGroup = new GeometryGroup();

            geometryGroup.FillRule = FillRule.Nonzero;
            geometryGroup.Children.Add(roundedRectangleGeometry);
            geometryGroup.Children.Add(balloonGeometry);

            if (geometryGroup.CanFreeze)
            {
                geometryGroup.Freeze();
            }

            RadialGradientBrush radialGradientBrush = new RadialGradientBrush();
            GradientStop gradientStop1 = new GradientStop(Color.FromArgb(Byte.MaxValue, Byte.MaxValue, Byte.MaxValue, Byte.MaxValue), 0);
开发者ID:kawatan,项目名称:Apricot,代码行数:67,代码来源:Balloon.xaml.cs

示例11: OnRendering


//.........这里部分代码省略.........
                                                {
                                                    if (this.hoverEmbeddedIndex.HasValue && this.hoverEmbeddedIndex.Value == inlineIndex1)
                                                    {
                                                        scrollStep = new Nullable<double>(1);
                                                        this.embedScrollStepDictionary.Add(inlineIndex1, 1);
                                                    }
                                                }
                                                else
                                                {
                                                    scrollStep = new Nullable<double>(step);
                                                    this.embedScrollStepDictionary.Add(inlineIndex1, step);
                                                }
                                            }

                                            if (this.embedColorStepDictionary.TryGetValue(inlineIndex1, out step2))
                                            {
                                                if (isReady && this.nextHistoryPoint.HasValue)
                                                {
                                                    if (!this.embedScrollStepDictionary.ContainsKey(inlineIndex1))
                                                    {
                                                        step2 -= 1 / (averageFrameRate / 4);
                                                    }

                                                    if (step2 <= 0)
                                                    {
                                                        entry = null;
                                                        isMutable = true;
                                                        this.embedColorStepDictionary.Remove(inlineIndex1);
                                                    }
                                                    else if (step2 < 1)
                                                    {
                                                        brush = new SolidColorBrush(Color.FromArgb((byte)(this.textColor.A + (this.linkColor.A - this.textColor.A) * Math.Sin(step2 / 2 * Math.PI)), (byte)(this.textColor.R + (this.linkColor.R - this.textColor.R) * Math.Sin(step2 / 2 * Math.PI)), (byte)(this.textColor.G + (this.linkColor.G - this.textColor.G) * Math.Sin(step2 / 2 * Math.PI)), (byte)(this.textColor.B + (this.linkColor.B - this.textColor.B) * Math.Sin(step2 / 2 * Math.PI))));

                                                        if (brush.CanFreeze)
                                                        {
                                                            brush.Freeze();
                                                        }

                                                        isMutable = true;
                                                        this.embedColorStepDictionary[inlineIndex1] = step2;
                                                    }
                                                    else
                                                    {
                                                        brush = this.linkBrush;
                                                    }
                                                }
                                                else if (step2 < 1)
                                                {
                                                    step2 += 1 / (averageFrameRate / 4);

                                                    if (step2 >= 1)
                                                    {
                                                        brush = this.linkBrush;
                                                        isMutable = true;
                                                        this.embedColorStepDictionary[inlineIndex1] = 1;
                                                    }
                                                    else
                                                    {
                                                        brush = new SolidColorBrush(Color.FromArgb((byte)(this.textColor.A + (this.linkColor.A - this.textColor.A) * Math.Sin(step2 / 2 * Math.PI)), (byte)(this.textColor.R + (this.linkColor.R - this.textColor.R) * Math.Sin(step2 / 2 * Math.PI)), (byte)(this.textColor.G + (this.linkColor.G - this.textColor.G) * Math.Sin(step2 / 2 * Math.PI)), (byte)(this.textColor.B + (this.linkColor.B - this.textColor.B) * Math.Sin(step2 / 2 * Math.PI))));

                                                        if (brush.CanFreeze)
                                                        {
                                                            brush.Freeze();
                                                        }

                                                        isMutable = true;
开发者ID:kawatan,项目名称:Apricot,代码行数:67,代码来源:Balloon.xaml.cs

示例12: GetDefiningGeometry

        protected virtual Geometry GetDefiningGeometry()
        {
            bool isStartVisible = IsStartVisible;
            bool isEndVisible = IsEndVisible;

            double radius = Radius;
            double thickness = GetThickness();

            double sx = X1;
            double sy = Y1;
            double ex = X2;
            double ey = Y2;

            double zet = LineUtil.Zet(sx, sy, ex, ey);
            double width = LineUtil.Width(radius, thickness, zet);
            double height = LineUtil.Height(radius, thickness, zet);

            bool shortenStart = GetShortenStart(this);
            bool shortenEnd = GetShortenEnd(this);
            bool isStartIO = GetStartIO();
            bool isEndIO = GetEndIO();

            // shorten start
            if (isStartIO == true && isEndIO == false && shortenStart == true)
            {
                if (Math.Round(sy, 1) == Math.Round(ey, 1))
                    sx = ex - ShortenLineSize;
            }

            // shorten end
            if (isStartIO == false && isEndIO == true && shortenEnd == true)
            {
                if (Math.Round(sy, 1) == Math.Round(ey, 1))
                    ex = sx + ShortenLineSize;
            }

            // get ellipse position
            IPoint ellipseStart = LineUtil.EllipseStart(sx, sy, width, height, isStartVisible);
            IPoint ellipseEnd = LineUtil.EllipseEnd(ex, ey, width, height, isEndVisible);

            // get line position
            IPoint lineStart = LineUtil.LineStart(sx, sy, width, height, isStartVisible);
            IPoint lineEnd = LineUtil.LineEnd(ex, ey, width, height, isEndVisible);

            var g = new GeometryGroup() { FillRule = FillRule.Nonzero };

            if (isStartVisible == true)
            {
                var startEllipse = new EllipseGeometry(
                    new Point(ellipseStart.X, ellipseStart.Y),
                    radius, radius);

                g.Children.Add(startEllipse);
            }

            if (isEndVisible == true)
            {
                var endEllipse = new EllipseGeometry(
                    new Point(ellipseEnd.X, ellipseEnd.Y),
                    radius, radius);

                g.Children.Add(endEllipse);
            }

            var line = new LineGeometry(
                new Point(lineStart.X, lineStart.Y),
                new Point(lineEnd.X, lineEnd.Y));

            g.Children.Add(line);

            g.Freeze();
            return g;
        }
开发者ID:elsiete,项目名称:CanvasDiagramEditor,代码行数:73,代码来源:LineEx.cs


注:本文中的System.Windows.Media.GeometryGroup.Freeze方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。