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


C# DrawingGroup.Append方法代码示例

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


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

示例1: CreateDottedImage

		public static int[] CreateDottedImage(int width, int height)
		{
			Random rnd = new Random();
			const int pointsNum = 100000;
			const double radius = 1.5;

			var randomPoints = Enumerable.Range(0, pointsNum).Select(_ => new Point(rnd.NextDouble() * width, rnd.NextDouble() * height));
			randomPoints = Filter(randomPoints, radius);

			DrawingGroup drawing = new DrawingGroup();
			var dc = drawing.Append();
			foreach (var point in randomPoints)
			{
				HsbColor color = new HsbColor(0, 0, Math.Round(5 * rnd.NextDouble()) / 4);
				SolidColorBrush brush = new SolidColorBrush(color.ToArgbColor());

				//drawing.Children.Add(new GeometryDrawing(brush, null, new EllipseGeometry(point, radius, radius)));
				dc.DrawEllipse(brush, null, point, radius, radius);
			}
			dc.Close();

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

			if ((imageCreatingThread.ThreadState | ThreadState.Running) != imageCreatingThread.ThreadState)
				imageCreatingThread.Start();
			imageQueue.Add(new RequestInfo { Width = width, Heigth = height, DrawingImage = drawingImage });
			var pixels = resultQueue.Take();

			return pixels;
		}
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:32,代码来源:ImageHelper.cs

示例2: SetImage

        public void SetImage()
        {
            var text = String.IsNullOrWhiteSpace(textBox.Text) ? "Enter some text above" : textBox.Text;
            //preview.Source = Renderer.RenderImage(text);

            const int width = 300;

            var words = new List<TextSegment>();

            var output = new DrawingGroup();

            //TextLines always include a line terminator, even for the last line in the string.
            string fullText = text + "\n";

            int lineStart = 0;	//In characters
            double top = 0;		//In pixels
            foreach (var line in Measurer.MeasureLines(text, width, format, output)) {
                int lastSpace = lineStart;
                while (lastSpace < lineStart + line.Length - 1) {
                    while (lastSpace < lineStart + line.Length && Char.IsWhiteSpace(fullText[lastSpace]))
                        lastSpace++;	//Skip over the previous chunk of whitespace

                    if (lastSpace == lineStart + line.Length)
                        continue;		//If the line ends in whitespace, skip it entirely

                    //Find the next space within this line
                    int nextSpace = fullText.IndexOfAny(whitespaceChars, lastSpace + 1, line.Length - (lastSpace + 1 - lineStart));

                    if (nextSpace < 0)		//Include the last word, even if it doesn't end with a space.
                        nextSpace = lineStart + line.Length - 1;

                    //if (nextSpace == lastSpace) continue;	//Entirely Skip double spaces

                    var word = text.Substring(lastSpace, nextSpace - lastSpace);
                    var bounds = line.GetTextBounds(lastSpace, word.Length);

                    //bounds is relative to the line
                    words.Add(new TextSegment(Rect.Offset(bounds[0].Rectangle, 0, top), word));

                    lastSpace = nextSpace;
                }
                lineStart += line.Length;
                top += line.Height;
                line.Dispose();
            }

            using (var dc = output.Append()) {
                var pen = new Pen(new SolidColorBrush(Color.FromArgb(128, 0, 0, 255)), 1);
                foreach (var word in words) {
                    dc.DrawRectangle(null, pen, word.Bounds);
                }
            }

            preview.Source = new DrawingImage(output);
        }
开发者ID:Amichai,项目名称:Prax,代码行数:55,代码来源:MainWindow.xaml.cs


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