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; }
public static Sm.DrawingGroup ToGeometryGroup(this Drawing input) { Sm.DrawingGroup drawings = new Sm.DrawingGroup(); double scale = input.GetScale(); Rg.Curve curve = input.Frame.ToNurbsCurve(); double x0 = input.Frame.Center.X - input.Width / scale / 2; double x1 = input.Frame.Center.X + input.Width / scale / 2; double y0 = input.Frame.Center.Y - input.Height / scale / 2; double y1 = input.Frame.Center.Y + input.Height / scale / 2; Rg.Rectangle3d rect = new Rg.Rectangle3d(Rg.Plane.WorldXY, new Rg.Point3d(x0, y0, 0), new Rg.Point3d(x1, y1, 0)); drawings.Children.Add(new Shape(rect.ToNurbsCurve(), new Wg.Graphic(Wg.Strokes.Transparent, new Wg.Fill(input.Background))).ToGeometryDrawing()); foreach (Shape shape in input.Shapes) { drawings.Children.Add(shape.ToGeometryDrawing()); } drawings.ClipGeometry = input.Frame.ToPolyline().ToGeometry(); Sm.TransformGroup xform = new Sm.TransformGroup(); xform.Children.Add(new Sm.TranslateTransform(input.Frame.Center.X - input.Width / 2, input.Frame.Center.Y - input.Height / 2)); xform.Children.Add(new Sm.ScaleTransform(1, -1)); drawings.Transform = xform; return(drawings); }
private Brush CreateARectangleWithDrawingBrush() { // Create a DrawingBrush DrawingBrush blackBrush = new DrawingBrush(); // Create a Geometry with white background GeometryDrawing backgroundSquare = new GeometryDrawing( Brushes.DarkGray, null, new RectangleGeometry(new Rect(0, 0, 400, 400))); // Create a GeometryGroup that will be added to Geometry GeometryGroup gGroup = new GeometryGroup(); gGroup.Children.Add(new RectangleGeometry(new Rect(0, 0, 200, 200))); gGroup.Children.Add(new RectangleGeometry(new Rect(200, 200, 200, 200))); // Create a GeomertyDrawing GeometryDrawing checkers = new GeometryDrawing(new SolidColorBrush(Colors.Gray), null, gGroup); DrawingGroup checkersDrawingGroup = new DrawingGroup(); checkersDrawingGroup.Children.Add(backgroundSquare); checkersDrawingGroup.Children.Add(checkers); blackBrush.Drawing = checkersDrawingGroup; // Set Viewport and TimeMode blackBrush.Viewport = new Rect(0, 0, 0.1, 0.2); blackBrush.TileMode = TileMode.Tile; return blackBrush; }
/// <summary> /// Initializes a new instance of the KinectBodyView class /// </summary> /// <param name="kinectSensor">Active instance of the KinectSensor</param> public KinectBodyView(KinectSensor kinectSensor) { if (kinectSensor == null) { throw new ArgumentNullException("kinectSensor"); } // get the coordinate mapper _coordinateMapper = kinectSensor.CoordinateMapper; // get the depth (display) extents FrameDescription frameDescription = kinectSensor.DepthFrameSource.FrameDescription; // get size of joint space _displayWidth = frameDescription.Width; _displayHeight = frameDescription.Height; // Create the drawing group we'll use for drawing _drawingGroup = new DrawingGroup(); // Create an image source that we can use in our image control _imageSource = new DrawingImage(_drawingGroup); }
public ProjectorViewWindow() { InitializeComponent(); drawingGroup = new DrawingGroup(); var imageSource = new DrawingImage(drawingGroup); Display.Source = imageSource; }
public static Sm.Drawing ToGeometryDrawing(this Shape input) { Sm.GeometryDrawing geometryDrawing = new Sm.GeometryDrawing(); Sm.GeometryGroup drawing = new Sm.GeometryGroup(); if (input.IsCompound) { foreach (Geometry geo in input.Geometries) { Sm.Geometry geometry = geo.ToGeometry(); drawing.Children.Add(geometry); } } else { Sm.Geometry geometry = input.ToGeometry(); drawing.Children.Add(geometry); } geometryDrawing.Geometry = drawing; geometryDrawing.Pen = input.Graphic.Stroke.ToMediaPen(); geometryDrawing.Brush = input.Graphic.Fill.ToMediaBrush(); Sm.DrawingGroup drawingGroup = new Sm.DrawingGroup(); drawingGroup.Children.Add(geometryDrawing); return(drawingGroup); }
private void PaintBackground() { var backgroundSquare = new GeometryDrawing(Brushes.Black, null, new RectangleGeometry(new Rect(0, 0, 100, 100))); var aGeometryGroup = new GeometryGroup(); aGeometryGroup.Children.Add(new RectangleGeometry(new Rect(0, 0, 50, 50))); aGeometryGroup.Children.Add(new RectangleGeometry(new Rect(50, 50, 50, 50))); var checkerBrush = new LinearGradientBrush(); checkerBrush.GradientStops.Add(new GradientStop(Colors.Black, 0.0)); checkerBrush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 22, 0), 1.0)); var checkers = new GeometryDrawing(checkerBrush, null, aGeometryGroup); var checkersDrawingGroup = new DrawingGroup(); checkersDrawingGroup.Children.Add(backgroundSquare); checkersDrawingGroup.Children.Add(checkers); var myBrush = new DrawingBrush { Drawing = checkersDrawingGroup, Viewport = new Rect(0, 0, 0.02, 0.02), TileMode = TileMode.Tile, Opacity = 0.5 }; LayoutRoot.Background = myBrush; }
public override void Render(WpfDrawingRenderer renderer) { Geometry clipGeom = this.ClipGeometry; Transform transform = this.Transform; if (clipGeom != null || transform != null) { WpfDrawingContext context = renderer.Context; _drawGroup = new DrawingGroup(); DrawingGroup currentGroup = context.Peek(); if (currentGroup == null) { throw new InvalidOperationException("An existing group is expected."); } currentGroup.Children.Add(_drawGroup); context.Push(_drawGroup); if (clipGeom != null) { _drawGroup.ClipGeometry = clipGeom; } if (transform != null) { _drawGroup.Transform = transform; } } base.Render(renderer); }
public object Convert (object [] values, Type targetType, object parameter, CultureInfo culture) { Brush foreground; //FIXME: How is it used? bool is_indeterminate; double indicator_lenght_in_orientation_direction; double indicator_lenght_in_other_direction; double track_lenght_in_orientation_direction; try { foreground = (Brush)values [0]; is_indeterminate = (bool)values [1]; indicator_lenght_in_orientation_direction = (double)values [2]; indicator_lenght_in_other_direction = (double)values [3]; track_lenght_in_orientation_direction = (double)values [4]; } catch (InvalidCastException) { return null; } const double LineWidth = 6; const double LineSpacing = 2; DrawingGroup drawing = new DrawingGroup (); DrawingContext drawing_context = drawing.Open (); int lines = (int)Math.Ceiling (indicator_lenght_in_orientation_direction / (LineWidth + LineSpacing)); int line_index; for (line_index = 0; line_index < lines - 1; line_index++) drawing_context.DrawRectangle (foreground, null, new Rect (line_index * (LineWidth + LineSpacing), 0, LineWidth, indicator_lenght_in_other_direction)); drawing_context.DrawRectangle (foreground, null, new Rect (line_index * (LineWidth + LineSpacing), 0, indicator_lenght_in_orientation_direction - (lines - 1) * (LineWidth + LineSpacing), indicator_lenght_in_other_direction)); drawing_context.Close (); DrawingBrush result = new DrawingBrush (drawing); result.Stretch = Stretch.None; result.Viewbox = new Rect (new Size (indicator_lenght_in_orientation_direction, indicator_lenght_in_other_direction)); result.Viewport = result.Viewbox; return result; }
/// <summary> /// Create a new abstract shape. /// </summary> /// <param name="Id">The Id of the shape.</param> /// <param name="Latitude">The latitude of the shape center.</param> /// <param name="Longitude">The longitude of the shape center.</param> /// <param name="Altitude">The altitude of the shape center.</param> /// <param name="GeoWidth">The geographical width of the shape center.</param> /// <param name="GeoHeight">The geographical height of the shape center.</param> public AShape(String[] Geometries, Latitude Latitude, Longitude Longitude, Altitude Altitude, Latitude Latitude2, Longitude Longitude2, Color StrokeColor, Double StrokeThickness, Color FillColor) { this.Id = Id; this.Latitude = Latitude; this.Longitude = Longitude; this.Altitude = Altitude; this.Latitude2 = Latitude2; this.Longitude2 = Longitude2; var PathGeometry16 = PathGeometry.Parse(Geometries[8]); var GD16 = new GeometryDrawing(new SolidColorBrush(FillColor), new Pen(new SolidColorBrush(StrokeColor), StrokeThickness), PathGeometry16); var DrawingGroup = new DrawingGroup(); DrawingGroup.Children.Add(GD16); this.Fill = new DrawingBrush() { Drawing = DrawingGroup, //Viewport = new Rect(0, 0, 1, 1), TileMode = TileMode.None, Stretch = Stretch.UniformToFill }; Bounds = DrawingGroup.Bounds; var w = Bounds.Width; var h = Bounds.Height; }
public ImageSource Draw() { var drawing = new DrawingGroup(); //background drawing.DrawRectangle(new Rect(-5, -100, 300, 200), Brushes.White, new Pen(Brushes.AntiqueWhite, 1)); //5 point marker drawing.DrawLine(new Point(200, -100), new Point(200, 100), Brushes.BurlyWood); drawing.DrawText(201, -7, "5"); //10 point marker drawing.DrawLine(new Point(220, -100), new Point(220, 100), Brushes.BurlyWood); drawing.DrawText(221, -7, "10"); //20 point marker drawing.DrawLine(new Point(240, -100), new Point(240, 100), Brushes.BurlyWood); drawing.DrawText(241, -7, "20"); //50 point marker drawing.DrawLine(new Point(260, -100), new Point(260, 100), Brushes.BurlyWood); drawing.DrawText(261, -7, "50"); drawing.DrawLine(new Point(280, -100), new Point(280, 100), Brushes.BurlyWood); drawing.DrawText(281, -7, "0"); //disc drawing.DrawCircle(new Point(_discXPosition, 0), 3, Brushes.Red); return new DrawingImage(drawing); }
protected override void OnRender(System.Windows.Media.DrawingContext drawingContext) { base.OnRender(drawingContext); // allows the points to be rendered as an image that can be further manipulated PathGeometry geometry = new PathGeometry(); this.Siz // Add all points to the geometry foreach (Points pointXY in _points) { PathFigure figure = new PathFigure(); figure.StartPoint = pointXY.FromPoint; figure.Segments.Add(new LineSegment(pointXY.ToPoint, true)); geometry.Figures.Add(figure); } // Add the first point to close the gap from the graph's end point // to graph's start point PathFigure lastFigure = new PathFigure(); lastFigure.StartPoint = _points[_points.Count - 1].FromPoint; lastFigure.Segments.Add(new LineSegment(_firstPoint, true)); geometry.Figures.Add(lastFigure); // Create a new drawing and drawing group in order to apply // a custom drawing effect GeometryDrawing drawing = new GeometryDrawing(this.Pen.Brush, this.Pen, geometry); DrawingGroup drawingGroup = new DrawingGroup(); drawingGroup.Children.Add(drawing); }
public DepthViewWindow(MainWindow parent) { InitializeComponent(); _running = true; drawingGroup = new DrawingGroup(); //parent.OnDepthFrameReceived += new GiveDepthFrame(GiveFrame); }
public MainWindow() { // Get the sensor sensor = KinectSensor.GetDefault(); sensor.Open(); // Setup readers for each source of data we want to use colorFrameReader = sensor.ColorFrameSource.OpenReader(); bodyFrameReader = sensor.BodyFrameSource.OpenReader(); // Setup event handlers that use what we get from the readers colorFrameReader.FrameArrived += this.Reader_ColorFrameArrived; bodyFrameReader.FrameArrived += this.Reader_BodyFrameArrived; // Get ready to draw graphics drawingGroup = new DrawingGroup(); // Initialize the components (controls) of the window InitializeComponent(); // Initialize color components // create the bitmap to display colorBitmap = new WriteableBitmap(1920, 1080, 96.0, 96.0, PixelFormats.Bgr32, null); ColorImage.Source = colorBitmap; // Initialize the game components birdHeight = this.Height / 2; // put the bird in the middle of the screen prevRightHandHeight = 0; prevLeftHandHeight = 0; pipeX = -1; pipeGapY = 250; pipeGapLength = 170; randomGenerator = new Random(); }
void MainWindow_Loaded(object sender, RoutedEventArgs e) { if (KinectSensor.KinectSensors.Count > 0) { this.sensor = KinectSensor.KinectSensors[0]; if (!this.sensor.IsRunning) { this.sensor.DepthStream.Range = DepthRange.Near; this.sensor.DepthFrameReady += sensor_DepthFrameReady; this.sensor.DepthStream.Enable(); this.sensor.SkeletonStream.EnableTrackingInNearRange = true; this.sensor.SkeletonStream.TrackingMode = SkeletonTrackingMode.Seated; this.sensor.SkeletonFrameReady += sensor_SkeletonFrameReady; this.sensor.SkeletonStream.Enable(); this.sensor.Start(); } this.drawingGroup = new DrawingGroup(); this.imageSource = new DrawingImage(this.drawingGroup); this.SkeletonController.Source = this.imageSource; } }
// disable default rendering public override void BeforeRender(WpfDrawingRenderer renderer) { base.BeforeRender(renderer); _matrix = Matrix.Identity; WpfDrawingContext context = renderer.Context; _drawGroup = new DrawingGroup(); //string elementId = this.GetElementName(); //if (!String.IsNullOrEmpty(elementId)) //{ // _drawGroup.SetValue(FrameworkElement.NameProperty, elementId); //} DrawingGroup currentGroup = context.Peek(); if (currentGroup == null) { throw new InvalidOperationException("An existing group is expected."); } currentGroup.Children.Add(_drawGroup); context.Push(_drawGroup); }
public override void BeforeRender(WpfDrawingRenderer renderer) { base.BeforeRender(renderer); WpfDrawingContext context = renderer.Context; _drawGroup = new DrawingGroup(); string elementId = this.GetElementName(); if (!String.IsNullOrEmpty(elementId) && !context.IsRegisteredId(elementId)) { _drawGroup.SetValue(FrameworkElement.NameProperty, elementId); context.RegisterId(elementId); if (context.IncludeRuntime) { SvgObject.SetId(_drawGroup, elementId); } } DrawingGroup currentGroup = context.Peek(); if (currentGroup == null) { throw new InvalidOperationException("An existing group is expected."); } currentGroup.Children.Add(_drawGroup); context.Push(_drawGroup); }
public HudRenderer(DrawingGroup drawGroup, DrawingImage drawImage, int width, int height) { drawingGroup = drawGroup; drawingImage = drawImage; displayHeight = height; displayWidth = width; }
public ImageSource Draw() { var drawing = new DrawingGroup(); //background drawing.DrawRectangle(new Rect(-5, -210, 300, 220), Brushes.White, new Pen(Brushes.AntiqueWhite, 1)); drawing.DrawLine(new Point(-5, 0), new Point(295, 0), Brushes.AntiqueWhite); //5 point marker drawing.DrawLine(new Point(200, -210), new Point(200, 10), Brushes.BurlyWood); drawing.DrawText(201, -107, "5"); //10 point marker drawing.DrawLine(new Point(220, -210), new Point(220, 10), Brushes.BurlyWood); drawing.DrawText(221, -107, "10"); //20 point marker drawing.DrawLine(new Point(240, -210), new Point(240, 10), Brushes.BurlyWood); drawing.DrawText(241, -107, "20"); //50 point marker drawing.DrawLine(new Point(260, -210), new Point(260, 10), Brushes.BurlyWood); drawing.DrawText(261, -107, "50"); drawing.DrawLine(new Point(280, -210), new Point(280, 10), Brushes.BurlyWood); drawing.DrawText(281, -107, "0"); //disc drawing.DrawCircle(_cannonballPosition, 1.5, Brushes.Black); var imageDrawing = new ImageDrawing(ResourceProvider.GetImage(Images.Cannon), new Rect(0, -25, 34.0, 24.4)); drawing.Children.Add(imageDrawing); return new DrawingImage(drawing); }
public void Init() { DrawingGroup dg = new DrawingGroup(); ImageDrawing id = new ImageDrawing(UnderlayImage, new Rect(0, 0, UnderlayImage.PixelWidth, UnderlayImage.PixelHeight)); dg.Children.Add(id); pointsGeometryGroup = new GeometryGroup(); linesGeometryGroup = new GeometryGroup(); middlePointGeoGrp = new GeometryGroup(); if (points != null) { SetPointsGeometry(); } GeometryDrawing gd = new GeometryDrawing(Brushes.Blue, null, pointsGeometryGroup); dg.Children.Add(gd); GeometryDrawing gd2 = new GeometryDrawing(null, new Pen(Brushes.LightGreen,3), linesGeometryGroup); dg.Children.Add(gd2); GeometryDrawing gd1 = new GeometryDrawing(Brushes.Red, null, middlePointGeoGrp); dg.Children.Add(gd1); Brush b = new SolidColorBrush(Colors.Red); b.Opacity = 0.5; mousePointGeometryDrwaing = new GeometryDrawing(b, null, null); dg.Children.Add(mousePointGeometryDrwaing); DrawingImage di = new DrawingImage(dg); this.Source = di; chosenPoint = -1; }
public MainWindow() { drawingGroup = new DrawingGroup(); imageSource = new DrawingImage( drawingGroup ); this.DataContext = this; InitializeComponent(); }
/// <summary> /// Creates a new screen /// </summary> public Screen(int width, int height, int fps) { Fps = Config.Get("Fps", fps); base.Width = Config.Get("ScreenWidth", width); base.Height = Config.Get("ScreenHeight", height); Trace.Info("new Screen(Fps = {0}, Width = {1}, Height = {2})", Fps, Width, Height); _dirty = true; _clipping = new Rect(0, 0, Width, Height); _backBuffer = new DrawingImage(_buffer = new DrawingGroup()); _keyMapping = Module.Get<IKeyMapping>(); (_window = new Window() { WindowStyle = WindowStyle.None, ResizeMode = ResizeMode.NoResize, WindowStartupLocation = WindowStartupLocation.CenterScreen, Content = this, SizeToContent = SizeToContent.WidthAndHeight, }).Show(); _window.KeyDown += _window_KeyDown; _window.KeyUp += _window_KeyUp; (_refreshTimer = new Timer(FrameTime)).Update += OnRenderCallback; }
public void SetFillBrush() { DrawingGroup rootDrawingGroup = new DrawingGroup(); GeometryDrawing aDrawing = new GeometryDrawing(); aDrawing.Brush = Brushes.Gray.CloneCurrentValue(); aDrawing.Pen = new Pen(Brushes.Gray, 1); aDrawing.Brush.Opacity = .5; aDrawing.Geometry = Primitives.PolygonLine(WallElementDetails.StartPoint, WallElementDetails.EndPoint, 10, 10); rootDrawingGroup.Children.Add(aDrawing); //create a transition line GeometryDrawing aCenterLine = new GeometryDrawing(); aCenterLine.Brush = Brushs.WallBoundaryStroke; aCenterLine.Pen = Pens.WallBoundaryStroke; aCenterLine.Geometry = Primitives.Line(WallElementDetails.StartPoint, WallElementDetails.EndPoint); rootDrawingGroup.Children.Add(aCenterLine); DrawingBrush brush = new DrawingBrush(rootDrawingGroup); this.Fill = brush; }
public MainWindow() { InitializeComponent(); drawingGroup = new DrawingGroup(); // Создаем объект для описания геометрической фигуры GeometryDrawing geometryDrawing = new GeometryDrawing(); // Описываем и сохраняем геометрию квадрата RectangleGeometry rectGeometry = new RectangleGeometry(); rectGeometry.Rect = new Rect(0, 0, 10, 10); geometryDrawing.Geometry = rectGeometry; // Настраиваем перо и кисть geometryDrawing.Pen = new Pen(Brushes.Red, 0.005);// Перо рамки geometryDrawing.Brush = Brushes.LightBlue;// Кисть закраски // Добавляем готовый слой в контейнер отображения drawingGroup.Children.Add(geometryDrawing); GeometryDrawing ellipsgeomy = new GeometryDrawing(); EllipseGeometry elgeometry = new EllipseGeometry(new Point(5, 5), 2, 2); ellipsgeomy.Geometry = elgeometry; ellipsgeomy.Brush = Brushes.White; drawingGroup.Children.Add(ellipsgeomy); }
public AreaSeries2D() { // 初始化保存数据点的变量 _points = new SeriesPointCollection(); _points.CollectionChanged += _points_CollectionChanged; // 初始化绘制曲线的画板 gStream_Line = new StreamGeometry(); gStream_Area = new StreamGeometry(); gDrawing_Line = new GeometryDrawing(); gDrawing_Line.Brush = null; gDrawing_Line.Pen = new Pen() { Thickness = 1, Brush = Brushes.Black }; gDrawing_Line.Geometry = gStream_Line; /* 初始化绘制填充色的画板 */ gDrawing_Area = new GeometryDrawing(); gDrawing_Area.Brush = Brushes.Red; gDrawing_Area.Pen = new Pen() { Thickness = 0, Brush = null }; gDrawing_Area.Geometry = gStream_Area; /* 生成绘画组 */ drawingGroup = new DrawingGroup(); drawingGroup.Children.Add(gDrawing_Line); drawingGroup.Children.Add(gDrawing_Area); }
private void Display_Loaded(object sender, RoutedEventArgs e) { drawingGroup = new DrawingGroup(); var imageSource = new DrawingImage(drawingGroup); Display.Source = imageSource; Redraw(); }
/// <summary> /// Construct new SelectionRectVisual object for the given rectangle /// </summary> public SelectionRectVisual(Point firstPointP, Point secondPointP, double zoomP) { DrawingGroup drawing = new DrawingGroup(); DrawingContext context = drawing.Open(); context.DrawRectangle(Brushes.White, null, new Rect(-1, -1, 3, 3)); context.DrawRectangle(Brushes.Black, null, new Rect(0.25, -1, 0.5, 3)); context.Close(); drawing.Freeze(); // Create a drawing brush that tiles the unit square from the drawing created above. // The size of the viewport and the rotation angle will be updated as we use the // dashed pen. DrawingBrush drawingBrush = new DrawingBrush(drawing); drawingBrush.ViewportUnits = BrushMappingMode.Absolute; drawingBrush.Viewport = new Rect(0, 0, _dashRepeatLength, _dashRepeatLength); drawingBrush.ViewboxUnits = BrushMappingMode.Absolute; drawingBrush.Viewbox = new Rect(0, 0, 1, 1); drawingBrush.Stretch = Stretch.Uniform; drawingBrush.TileMode = TileMode.Tile; // Store the drawing brush and a copy that's rotated by 90 degrees. _horizontalDashBrush = drawingBrush; _verticalDashBrush = drawingBrush.Clone(); _verticalDashBrush.Transform = new RotateTransform(90); this._firstPoint = firstPointP; this._secondPoint = secondPointP; this._zoom = zoomP; _visualForRect = new DrawingVisual(); this.AddVisualChild(_visualForRect); this.AddLogicalChild(_visualForRect); }
public BodyDrawer(CoordinateMapper coordinateMapper, FrameDescription frameDescription, DrawingGroup drawingGroup) { this.bonesToDraw = (new BodyInitializer()).GetBones(); this.coordinateMapper = coordinateMapper; this.displayHeight = frameDescription.Height; this.displayWidth = frameDescription.Width; this.drawingGroup = drawingGroup; }
/// <summary></summary> /// <param name="kinectConnector"></param> public KinectBodyDrawer(KinectConnector kinectConnector) { this.kinectConnector = kinectConnector; drawingGroup = new DrawingGroup(); ImageSource = new DrawingImage(drawingGroup); kinectConnector.BodyUpdated += (_, e) => Draw(e.Body); }
private Drawing buildDrawing() { DrawingGroup group = new DrawingGroup(); foreach (GraphElement element in this.elements) { group.Children.Add(element.buildDrawing()); } return group; }
public override Drawing Teken_jezelf() { var level = new DrawingGroup(); level.Children.Add(Teken_achtergrond()); level.Children.Add(Teken_monsterkes_en_hindernissen()); return level; }
//========================================================================== public override Drawing Draw() { DrawingGroup drawing_group = new DrawingGroup(); drawing_group.Opacity = Opacity.ToDouble(); if(Transform != null) drawing_group.Transform = Transform.ToTransform(); foreach(SvgBaseElement element in Children) { Drawing drawing = null; if(element is SvgDrawableBaseElement) drawing = (element as SvgDrawableBaseElement).Draw(); else if(element is SvgDrawableContainerBaseElement) drawing = (element as SvgDrawableContainerBaseElement).Draw(); if(drawing != null) drawing_group.Children.Add(drawing); } if(Filter != null) { SvgFilterElement filter_element = Document.Elements[Filter.Id] as SvgFilterElement; if(filter_element != null) drawing_group.BitmapEffect = filter_element.ToBitmapEffect(); } if(ClipPath != null) { SvgClipPathElement clip_path_element = Document.Elements[ClipPath.Id] as SvgClipPathElement; if(clip_path_element != null) drawing_group.ClipGeometry = clip_path_element.GetClipGeometry(); } if(Mask != null) { SvgMaskElement mask_element = Document.Elements[Mask.Id] as SvgMaskElement; if(mask_element != null) { drawing_group.OpacityMask = mask_element.GetOpacityMask(); GeometryGroup geometry_group = new GeometryGroup(); if(drawing_group.ClipGeometry != null) geometry_group.Children.Add(drawing_group.ClipGeometry); geometry_group.Children.Add(mask_element.GetClipGeometry()); drawing_group.ClipGeometry = geometry_group; } } return drawing_group; }
public void InitializeSkeleton() { this.coordinateMapper = this.kinectSensor.CoordinateMapper; // get the depth (display) extents FrameDescription frameDescription = this.kinectSensor.DepthFrameSource.FrameDescription; // get size of joint space this.displayWidth = frameDescription.Width; this.displayHeight = frameDescription.Height; // open the reader for the body frames this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader(); // a bone defined as a line between two joints this.bones = new List <Tuple <JointType, JointType> >(); // Torso this.bones.Add(new Tuple <JointType, JointType>(JointType.Head, JointType.Neck)); this.bones.Add(new Tuple <JointType, JointType>(JointType.Neck, JointType.SpineShoulder)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.SpineMid)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineMid, JointType.SpineBase)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineBase, JointType.HipRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineBase, JointType.HipLeft)); // Right Arm this.bones.Add(new Tuple <JointType, JointType>(JointType.ShoulderRight, JointType.ElbowRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.ElbowRight, JointType.WristRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristRight, JointType.HandRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.HandRight, JointType.HandTipRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristRight, JointType.ThumbRight)); // Left Arm this.bones.Add(new Tuple <JointType, JointType>(JointType.ShoulderLeft, JointType.ElbowLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.ElbowLeft, JointType.WristLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristLeft, JointType.HandLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.HandLeft, JointType.HandTipLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristLeft, JointType.ThumbLeft)); // open the sensor this.kinectSensor.Open(); // Create the drawing group we'll use for drawing this.drawingGroup = new DrawingGroup(); // Create an image source that we can use in our image control this.streamSkeleton.Source = new DrawingImage(this.drawingGroup); if (this.bodyFrameReader != null) { this.bodyFrameReader.FrameArrived += this.Reader_FrameArrived; } }
void CreateGroup() { if (baseContext == null) { baseContext = Control; } RewindAll(); group = new swm.DrawingGroup(); Control = group.Open(); ApplyAll(); }
void CreateGroup() { CloseGroup(); if (baseContext == null) { baseContext = Control; } group = new swm.DrawingGroup(); Control = group.Open(); TransformStack.PushAll(); ApplyClip(); }
void CloseGroup() { if (group != null && baseContext != null) { RewindAll(); Control.Close(); baseContext.DrawDrawing(group); Control = baseContext; group = null; ApplyAll(); } }
void CloseGroup() { if (group != null && baseContext != null) { TransformStack.PopAll(); ResetClip(); Control.Close(); baseContext.DrawDrawing(group); Control = baseContext; group = null; ApplyClip(); TransformStack.PushAll(); } }
public swmi.BitmapFrame Get(swmi.BitmapSource image, float scale, int width, int height, swm.BitmapScalingMode scalingMode) { if (width <= 0 || height <= 0 || scale <= 0) { return(null); } var _cachedFrame = _cachedFrameReference?.Target as swmi.BitmapFrame; // if parameters are the same, return cached bitmap if (_cachedFrame != null && scale == _scale && width == _width && height == _height && scalingMode == _scalingMode) { return(_cachedFrame); } // generate a new bitmap with the desired size & scale. var scaledwidth = (int)Math.Round(width * scale); var scaledheight = (int)Math.Round(height * scale); if (scaledwidth <= 0 || scaledheight <= 0) { return(null); } var group = new swm.DrawingGroup(); swm.RenderOptions.SetBitmapScalingMode(group, scalingMode); group.Children.Add(new swm.ImageDrawing(image, new sw.Rect(0, 0, width, height))); var targetVisual = new swm.DrawingVisual(); using (var targetContext = targetVisual.RenderOpen()) targetContext.DrawDrawing(group); // note, this uses a GDI handle, which are limited (only 5000 or so can be created). // There's no way to get around it other than just not creating that many and using GC.Collect/WaitForPendingFinalizers. // we can't do it in Eto as it'd be a serious performance hit. var target = new swmi.RenderTargetBitmap(scaledwidth, scaledheight, 96 * scale, 96 * scale, swm.PixelFormats.Default); target.Render(targetVisual); target.Freeze(); _cachedFrame = swmi.BitmapFrame.Create(target); _cachedFrame.Freeze(); _scale = scale; _width = width; _height = height; _scalingMode = scalingMode; _cachedFrameReference = new WeakReference(_cachedFrame); return(_cachedFrame); }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.board = ((System.Windows.Controls.Image)(target)); return; case 2: this.drawpage = ((System.Windows.Media.DrawingGroup)(target)); return; } this._contentLoaded = true; }
static swmi.BitmapFrame Resize(swmi.BitmapSource image, float scale, int width, int height, swm.BitmapScalingMode scalingMode) { var group = new swm.DrawingGroup(); swm.RenderOptions.SetBitmapScalingMode(group, scalingMode); group.Children.Add(new swm.ImageDrawing(image, new sw.Rect(0, 0, width, height))); var targetVisual = new swm.DrawingVisual(); var targetContext = targetVisual.RenderOpen(); targetContext.DrawDrawing(group); width = (int)Math.Round(width * scale); height = (int)Math.Round(height * scale); var target = new swmi.RenderTargetBitmap(width, height, 96 * scale, 96 * scale, swm.PixelFormats.Default); targetContext.Close(); target.Render(targetVisual); return(swmi.BitmapFrame.Create(target)); }
/// <summary> /// Resizes a bitmap frame /// </summary> /// <param name="photo"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="scalingMode"></param> /// <returns></returns> public static BitmapFrame Resize(BitmapFrame photo, int width, int height, System.Windows.Media.BitmapScalingMode scalingMode) { var group = new System.Windows.Media.DrawingGroup(); System.Windows.Media.RenderOptions.SetBitmapScalingMode(group, scalingMode); group.Children.Add(new System.Windows.Media.ImageDrawing(photo, new System.Windows.Rect(0, 0, width, height))); var targetVisual = new System.Windows.Media.DrawingVisual(); var targetContext = targetVisual.RenderOpen(); targetContext.DrawDrawing(group); var target = new RenderTargetBitmap(width, height, 96, 96, System.Windows.Media.PixelFormats.Default); targetContext.Close(); target.Render(targetVisual); var targetFrame = BitmapFrame.Create(target); return(targetFrame); }
public void Create(Image image, int width, int height, ImageInterpolation interpolation) { ApplicationHandler.InvokeIfNecessary(() => { var source = image.ToWpf(); // use drawing group to allow for better quality scaling var group = new swm.DrawingGroup(); swm.RenderOptions.SetBitmapScalingMode(group, interpolation.ToWpf()); group.Children.Add(new swm.ImageDrawing(source, new sw.Rect(0, 0, width, height))); var drawingVisual = new swm.DrawingVisual(); using (var drawingContext = drawingVisual.RenderOpen()) drawingContext.DrawDrawing(group); var resizedImage = new swm.Imaging.RenderTargetBitmap(width, height, source.DpiX, source.DpiY, swm.PixelFormats.Default); resizedImage.Render(drawingVisual); Control = resizedImage; }); }
//------------------------------------------------------ // // Public Properties // //------------------------------------------------------ private static void ChildrenPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { // The first change to the default value of a mutable collection property (e.g. GeometryGroup.Children) // will promote the property value from a default value to a local value. This is technically a sub-property // change because the collection was changed and not a new collection set (GeometryGroup.Children. // Add versus GeometryGroup.Children = myNewChildrenCollection). However, we never marshalled // the default value to the compositor. If the property changes from a default value, the new local value // needs to be marshalled to the compositor. We detect this scenario with the second condition // e.OldValueSource != e.NewValueSource. Specifically in this scenario the OldValueSource will be // Default and the NewValueSource will be Local. if (e.IsASubPropertyChange && (e.OldValueSource == e.NewValueSource)) { return; } DrawingGroup target = ((DrawingGroup)d); // If this is both non-null and mutable, we need to unhook the Changed event. DrawingCollection oldCollection = null; DrawingCollection newCollection = null; if ((e.OldValueSource != BaseValueSourceInternal.Default) || e.IsOldValueModified) { oldCollection = (DrawingCollection)e.OldValue; if ((oldCollection != null) && !oldCollection.IsFrozen) { oldCollection.ItemRemoved -= target.ChildrenItemRemoved; oldCollection.ItemInserted -= target.ChildrenItemInserted; } } // If this is both non-null and mutable, we need to hook the Changed event. if ((e.NewValueSource != BaseValueSourceInternal.Default) || e.IsNewValueModified) { newCollection = (DrawingCollection)e.NewValue; if ((newCollection != null) && !newCollection.IsFrozen) { newCollection.ItemInserted += target.ChildrenItemInserted; newCollection.ItemRemoved += target.ChildrenItemRemoved; } } if (oldCollection != newCollection && target.Dispatcher != null) { using (CompositionEngineLock.Acquire()) { DUCE.IResource targetResource = (DUCE.IResource)target; int channelCount = targetResource.GetChannelCount(); for (int channelIndex = 0; channelIndex < channelCount; channelIndex++) { DUCE.Channel channel = targetResource.GetChannel(channelIndex); Debug.Assert(!channel.IsOutOfBandChannel); Debug.Assert(!targetResource.GetHandle(channel).IsNull); // resource shouldn't be null because // 1) If the field is one of our collections, we don't allow null elements // 2) Codegen already made sure the collection contains DUCE.IResources // ... so we'll Assert it if (newCollection != null) { int count = newCollection.Count; for (int i = 0; i < count; i++) { DUCE.IResource resource = newCollection.Internal_GetItem(i) as DUCE.IResource; Debug.Assert(resource != null); resource.AddRefOnChannel(channel); } } if (oldCollection != null) { int count = oldCollection.Count; for (int i = 0; i < count; i++) { DUCE.IResource resource = oldCollection.Internal_GetItem(i) as DUCE.IResource; Debug.Assert(resource != null); resource.ReleaseOnChannel(channel); } } } } } target.PropertyChanged(ChildrenProperty); }
/// <summary> /// DrawingGroupDrawingContext populates a DrawingGroup from the Draw /// commands that are called on it. /// </summary> /// <param name="drawingGroup"> DrawingGroup this context populates </param> internal DrawingGroupDrawingContext(DrawingGroup drawingGroup) { Debug.Assert(null != drawingGroup); _drawingGroup = drawingGroup; }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.RadarWindow = ((Wpf.RadarWindow.MainWindow)(target)); #line 16 "..\..\MainWindow.xaml" this.RadarWindow.SizeChanged += new System.Windows.SizeChangedEventHandler(this.RadarWindow_SizeChanged); #line default #line hidden return; case 2: this.vbox = ((System.Windows.Controls.Grid)(target)); #line 26 "..\..\MainWindow.xaml" this.vbox.SizeChanged += new System.Windows.SizeChangedEventHandler(this.Grid_SizeChanged); #line default #line hidden return; case 3: this.img = ((System.Windows.Controls.Image)(target)); return; case 4: this.dg = ((System.Windows.Media.DrawingGroup)(target)); return; case 5: this.rect = ((System.Windows.Shapes.Rectangle)(target)); return; case 6: this.btResize = ((System.Windows.Controls.Primitives.ToggleButton)(target)); #line 52 "..\..\MainWindow.xaml" this.btResize.Click += new System.Windows.RoutedEventHandler(this.btResie_Click); #line default #line hidden return; case 7: this.btAntiPersonnel = ((System.Windows.Controls.Primitives.ToggleButton)(target)); return; case 8: this.btSelect = ((System.Windows.Controls.Primitives.ToggleButton)(target)); return; case 9: this.btZoomIn = ((System.Windows.Controls.Button)(target)); #line 233 "..\..\MainWindow.xaml" this.btZoomIn.Click += new System.Windows.RoutedEventHandler(this.btZoomIn_Click); #line default #line hidden return; case 10: this.btZoomOut = ((System.Windows.Controls.Button)(target)); return; case 11: this.btSwitch = ((System.Windows.Controls.Button)(target)); #line 252 "..\..\MainWindow.xaml" this.btSwitch.Click += new System.Windows.RoutedEventHandler(this.btSwitch_Click); #line default #line hidden return; case 12: this.rtClipBar = ((System.Windows.Shapes.Rectangle)(target)); return; case 13: this.btFlagOn = ((System.Windows.Controls.Button)(target)); return; } this._contentLoaded = true; }
public ImageChart() { _drawingGroup = new SWM.DrawingGroup(); }