/// <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 void drawArrow(Point x, Point y, Pen pen, Color penColor) { DrawingGroup drawing = new DrawingGroup(); drawing.Children.Add(new ImageDrawing(bmp, new Rect(0, 0, bmp.PixelWidth, bmp.PixelHeight))); drawing.Children.Add(new GeometryDrawing(pen.Brush, pen, Drawing.makeArrowGeometry(x, y, pen.Thickness))); drawing.ClipGeometry = new RectangleGeometry(new Rect(0, 0, bmp.PixelWidth, bmp.PixelHeight)); drawing.Freeze(); var image = new Image { Source = new DrawingImage(drawing) }; var bitmap = new RenderTargetBitmap(bmp.PixelWidth, bmp.PixelHeight, 96, 96, PixelFormats.Pbgra32); image.Arrange(new Rect(0, 0, bmp.PixelWidth, bmp.PixelHeight)); bitmap.Render(image); bmp = BitmapFactory.ConvertToPbgra32Format(bitmap); }
private void OnSelectPicture() { var openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Все файлы изображений|*.bmp; *.png; *.jpeg; *.jpg; *.svg|BMP Файлы|*.bmp|PNG Файлы|*.png|JPEG Файлы|*.jpeg|JPG Файлы|*.jpg|SVG Файлы|*.svg"; if (openFileDialog.ShowDialog().Value) { // TODO: ограничить размер файла _newImage = true; _sourceName = openFileDialog.FileName; _imageSource = null; _isVectorImage = VectorGraphicExtensions.Contains(Path.GetExtension(_sourceName)); if (_isVectorImage) { using (FileSvgReader reader = new FileSvgReader(_settings)) _drawing = reader.Read(_sourceName); _drawing.Freeze(); } UpdateImage(); } }
public void drawStamp(Point p, BitmapSource stamp, int size) { int stampWidth, stampHeight; if (stamp.PixelHeight > stamp.PixelWidth) { stampHeight = size; stampWidth = (int)((double)size * ((double)stamp.PixelWidth / (double)stamp.PixelHeight)); } else { stampHeight = (int)((double)size * ((double)stamp.PixelHeight / (double)stamp.PixelWidth)); stampWidth = size; } DrawingGroup drawing = new DrawingGroup(); drawing.Children.Add(new ImageDrawing(bmp, new Rect(0, 0, bmp.PixelWidth, bmp.PixelHeight))); drawing.Children.Add(new ImageDrawing(stamp, new Rect(p.X - stampWidth / 2, p.Y - stampHeight / 2, stampWidth, stampHeight))); drawing.ClipGeometry = new RectangleGeometry(new Rect(0, 0, bmp.PixelWidth, bmp.PixelHeight)); drawing.Freeze(); var image = new Image { Source = new DrawingImage(drawing) }; var bitmap = new RenderTargetBitmap(bmp.PixelWidth, bmp.PixelHeight, 96, 96, PixelFormats.Pbgra32); image.Arrange(new Rect(0, 0, bmp.PixelWidth, bmp.PixelHeight)); bitmap.Render(image); bmp = BitmapFactory.ConvertToPbgra32Format(bitmap); }
private void OnWorkerDoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = (BackgroundWorker)sender; _wpfSettings.IncludeRuntime = _options.IncludeRuntime; _wpfSettings.TextAsGeometry = _options.TextAsGeometry; _fileReader.UseFrameXamlWriter = !_options.UseCustomXamlWriter; if (_options.GeneralWpf) { _fileReader.SaveXaml = _options.SaveXaml; _fileReader.SaveZaml = _options.SaveZaml; } else { _fileReader.SaveXaml = false; _fileReader.SaveZaml = false; } _drawing = _fileReader.Read(_sourceFile, _outputInfoDir); if (_drawing == null) { e.Result = "Failed"; return; } if (_options.GenerateImage) { _fileReader.SaveImage(_sourceFile, _outputInfoDir, _options.EncoderType); _imageFile = _fileReader.ImageFile; } _xamlFile = _fileReader.XamlFile; _zamlFile = _fileReader.ZamlFile; if (_drawing.CanFreeze) { _drawing.Freeze(); } e.Result = "Successful"; }
public override ImageSource getTacticAt(int time) { if (staticTactics.ContainsKey(time)) { if (staticTactics[time].isClone) { return getTacticAt(staticTactics[time].cloneOriginalTime); } else { if (hasSampleLine) { DrawingGroup drawing = new DrawingGroup(); drawing.Children.Add(new ImageDrawing(staticTactics[time].map.getImage(), new Rect(0, 0, 1024, 1024))); drawing.Children.Add(new GeometryDrawing(samplePen.Brush, samplePen, new LineGeometry(sample.Key, sample.Value))); drawing.ClipGeometry = new RectangleGeometry(new Rect(0, 0, 1024, 1024)); drawing.Freeze(); return new DrawingImage(drawing); } else if (hasSampleArrow) { Pen pen = this.samplePen.Clone(); pen.EndLineCap = PenLineCap.Triangle; DrawingGroup drawing = new DrawingGroup(); drawing.Children.Add(new ImageDrawing(staticTactics[time].map.getImage(), new Rect(0, 0, 1024, 1024))); drawing.Children.Add(new GeometryDrawing(pen.Brush, pen, Drawing.makeArrowGeometry(sample.Key, sample.Value, pen.Thickness))); drawing.ClipGeometry = new RectangleGeometry(new Rect(0, 0, 1024, 1024)); drawing.Freeze(); return new DrawingImage(drawing); } else if (sampleStamp.size != 0) { int stampWidth, stampHeight; if (sampleStamp.stamp.PixelHeight > sampleStamp.stamp.PixelWidth) { stampHeight = sampleStamp.size; stampWidth = (int)((double)sampleStamp.size * ((double)sampleStamp.stamp.PixelWidth / (double)sampleStamp.stamp.PixelHeight)); } else { stampHeight = (int)((double)sampleStamp.size * ((double)sampleStamp.stamp.PixelHeight / (double)sampleStamp.stamp.PixelWidth)); stampWidth = sampleStamp.size; } DrawingGroup drawing = new DrawingGroup(); drawing.Children.Add(new ImageDrawing(staticTactics[time].map.getImage(), new Rect(0, 0, 1024, 1024))); drawing.Children.Add(new ImageDrawing(sampleStamp.stamp, new Rect(sampleStamp.p.X - stampWidth / 2, sampleStamp.p.Y - stampHeight / 2, stampWidth, stampHeight))); drawing.ClipGeometry = new RectangleGeometry(new Rect(0, 0, 1024, 1024)); drawing.Freeze(); return new DrawingImage(drawing); } else { return staticTactics[time].map.getImage(); } } } else { return clearTactic; } }
private void DrawTiles(System.Windows.Media.DrawingContext dc) { TilesWideObject = (int)(this.ActualWidth / 64) + 1; TilesHighObject = (int)(this.ActualHeight / 64) + 1; int startX = (int)CurrentPointObject.X - (TilesWideObject / 2); int startY = (int)CurrentPointObject.Y - (TilesHighObject / 2); if (startX < 0) startX = 0; if (startY < 0) startY = 0; int endX = startX + TilesWideObject; int endY = startY + TilesHighObject; if (endX > GameWorldObject.GameMapWidth) { endX = GameWorldObject.GameMapWidth; startX = endX - TilesWideObject; } else if (startX < 0) { startX = 0; endX = TilesWideObject; } if (endY > GameWorldObject.GameMapHeight) { endY = GameWorldObject.GameMapHeight; startY = endY - TilesHighObject; } else if (startY < 0) { startY = 0; endY = TilesHighObject; } int CountX = 0; int CountY = 0; DrawingGroup dg = new DrawingGroup(); for (int x = startX; x < endX; x++) { for (int y = startY; y < endY; y++) { dg.Children.Add( new ImageDrawing(_mapTiles[GameWorldObject.GameMap[x, y].GraphicsTile.TileStartPoint], new Rect(CountX * 64, CountY * 64, 64, 64) )); dg.Children.Add( new GeometryDrawing( null, new Pen( new SolidColorBrush( Color.FromRgb(255, 0, 20)), .3), new RectangleGeometry( new Rect(CountX * 64, CountY * 64, 64, 64) ) ) ); #if DEBUG if (x % 5 == 0 && y % 5 == 0) { FormattedText text = new FormattedText("X:" + x + " Y:" + y, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new System.Windows.Media.Typeface("arial"), 12, new SolidColorBrush(Color.FromRgb(255, 0, 20))); Geometry geometry = text.BuildGeometry(new Point(CountX * 64, CountY * 64)); GeometryDrawing gd = new GeometryDrawing(new SolidColorBrush(Color.FromRgb(255, 0, 20)), new Pen(), geometry); dg.Children.Add(gd); } #endif CountY++; } CountY = 0; CountX++; } dg.Freeze(); dc.DrawDrawing(dg); }
/// <summary> /// Constructor /// </summary> /// <param name="adornedElement">The adorned InkCanvas</param> internal InkCanvasSelectionAdorner(UIElement adornedElement) : base(adornedElement) { Debug.Assert(adornedElement is InkCanvasInnerCanvas, "InkCanvasSelectionAdorner only should be used by InkCanvas internally"); // Initialize the internal data. _adornerBorderPen = new Pen(Brushes.Black, 1.0); DoubleCollection dashes = new DoubleCollection( ); dashes.Add(4.5); dashes.Add(4.5); _adornerBorderPen.DashStyle = new DashStyle(dashes, 2.25); _adornerBorderPen.DashCap = PenLineCap.Flat; _adornerBorderPen.Freeze(); _adornerPenBrush = new Pen(new SolidColorBrush(Color.FromRgb(132, 146, 222)), 1); _adornerPenBrush.Freeze(); _adornerFillBrush = new LinearGradientBrush( Color.FromRgb(240, 242, 255), //start color Color.FromRgb(180, 207, 248), //end color 45f //angle ); _adornerFillBrush.Freeze(); // Create a hatch pen DrawingGroup hatchDG = new DrawingGroup( ); DrawingContext dc = null; try { dc = hatchDG.Open( ); dc.DrawRectangle( Brushes.Transparent, null, new Rect(0.0, 0.0, 1f, 1f)); Pen squareCapPen = new Pen(Brushes.Black, LineThickness); squareCapPen.StartLineCap = PenLineCap.Square; squareCapPen.EndLineCap = PenLineCap.Square; dc.DrawLine(squareCapPen, new Point(1f, 0f), new Point(0f, 1f)); } finally { if ( dc != null ) { dc.Close( ); } } hatchDG.Freeze(); DrawingBrush tileBrush = new DrawingBrush(hatchDG); tileBrush.TileMode = TileMode.Tile; tileBrush.Viewport = new Rect(0, 0, HatchBorderMargin, HatchBorderMargin); tileBrush.ViewportUnits = BrushMappingMode.Absolute; tileBrush.Freeze(); _hatchPen = new Pen(tileBrush, HatchBorderMargin); _hatchPen.Freeze(); _elementsBounds = new List<Rect>(); _strokesBounds = Rect.Empty; }
private DrawingGroup GetDrawingHelper() { // Printing an HWND requires UIPermissionWindow.AllWindows to give out its pixels. SecurityHelper.DemandUIWindowPermission(); DrawingGroup drawingGroup = null; if(_hwnd.Handle != IntPtr.Zero && UnsafeNativeMethods.IsWindow(_hwnd)) { NativeMethods.RECT rc = new NativeMethods.RECT(); SafeNativeMethods.GetWindowRect(_hwnd, ref rc); int width = rc.right - rc.left; int height = rc.bottom - rc.top; HandleRef hdcScreen = new HandleRef(this, UnsafeNativeMethods.GetDC(new HandleRef(this, IntPtr.Zero))); if(hdcScreen.Handle != IntPtr.Zero) { HandleRef hdcBitmap = new HandleRef(this, IntPtr.Zero); HandleRef hBitmap = new HandleRef(this, IntPtr.Zero); try { hdcBitmap = new HandleRef(this, UnsafeNativeMethods.CriticalCreateCompatibleDC(hdcScreen)); if(hdcBitmap.Handle != IntPtr.Zero) { hBitmap = new HandleRef(this, UnsafeNativeMethods.CriticalCreateCompatibleBitmap(hdcScreen, width, height)); if(hBitmap.Handle != IntPtr.Zero) { // Select the bitmap into the DC so that we draw to it. IntPtr hOldBitmap = UnsafeNativeMethods.CriticalSelectObject(hdcBitmap, hBitmap.Handle); try { // Clear the bitmap to white (so we don't waste toner printing a black bitmap something fails). NativeMethods.RECT rcPaint = new NativeMethods.RECT(0,0,width, height); IntPtr hbrWhite = UnsafeNativeMethods.CriticalGetStockObject(NativeMethods.WHITE_BRUSH); UnsafeNativeMethods.CriticalFillRect(hdcBitmap.Handle, ref rcPaint, hbrWhite); // First try to use the PrintWindow API. bool result = UnsafeNativeMethods.CriticalPrintWindow(_hwnd, hdcBitmap, 0); if(result == false) { // Fall back to sending a WM_PRINT message to the window. // // Note: there are known cases where WM_PRINT is not implemented // to provide visual parity with WM_PAINT. However, since the // GetDrawing method is virtual, the derived class can override // this default implementation and provide a better implementation. UnsafeNativeMethods.SendMessage(_hwnd.Handle, WindowMessage.WM_PRINT, hdcBitmap.Handle, (IntPtr) (NativeMethods.PRF_CHILDREN | NativeMethods.PRF_CLIENT | NativeMethods.PRF_ERASEBKGND | NativeMethods.PRF_NONCLIENT)); } else { // There is a know issue where calling PrintWindow on a window will // clear all dirty regions (but since it is redirected, the screen // won't be updated). As a result we can leave unpainted pixels on // the screen if PrintWindow is called when the window was dirty. // // To fix this, we just force the child window to repaint. // UnsafeNativeMethods.CriticalRedrawWindow(_hwnd, IntPtr.Zero, IntPtr.Zero, NativeMethods.RDW_INVALIDATE | NativeMethods.RDW_ALLCHILDREN); } // Create a DrawingGroup that only contains an ImageDrawing that wraps the bitmap. drawingGroup = new DrawingGroup(); System.Windows.Media.Imaging.BitmapSource bitmapSource = Imaging.CriticalCreateBitmapSourceFromHBitmap(hBitmap.Handle, IntPtr.Zero, Int32Rect.Empty, null, WICBitmapAlphaChannelOption.WICBitmapIgnoreAlpha); Rect rectElement = new Rect(RenderSize); drawingGroup.Children.Add(new ImageDrawing(bitmapSource, rectElement)); drawingGroup.Freeze(); } finally { // Put the old bitmap back into the DC. UnsafeNativeMethods.CriticalSelectObject(hdcBitmap, hOldBitmap); } } } } finally { UnsafeNativeMethods.ReleaseDC(new HandleRef(this, IntPtr.Zero), hdcScreen); hdcScreen = new HandleRef(null, IntPtr.Zero); if(hBitmap.Handle != IntPtr.Zero) { UnsafeNativeMethods.DeleteObject(hBitmap); hBitmap = new HandleRef(this, IntPtr.Zero); } if(hdcBitmap.Handle != IntPtr.Zero) { UnsafeNativeMethods.CriticalDeleteDC(hdcBitmap); hdcBitmap = new HandleRef(this, IntPtr.Zero); } } } } return drawingGroup; }
public HeliosVisualContainerEditor() { Focusable = true; _view = new HeliosVisualView(); _view.IgnoreHidden = true; _view.DisplayRotation = false; AddVisualChild(_view); SelectedItems = new HeliosVisualCollection(); _zoomCalibration = new CalibrationPointCollectionDouble(-4d, 0.25d, 4d, 4d); _zoomCalibration.Add(new CalibrationPointDouble(0d, 1d)); SelectedItems.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(SelectedItems_CollectionChanged); DrawingGroup checkerGroup = new DrawingGroup(); checkerGroup.Children.Add(new GeometryDrawing(Brushes.White, null, new RectangleGeometry(new Rect(0, 0, 100, 100)))); DrawingGroup grayGroup = new DrawingGroup(); grayGroup.Children.Add(new GeometryDrawing(Brushes.LightGray, null, new RectangleGeometry(new Rect(0, 0, 50, 50)))); grayGroup.Children.Add(new GeometryDrawing(Brushes.LightGray, null, new RectangleGeometry(new Rect(50, 50, 50, 50)))); checkerGroup.Children.Add(grayGroup); checkerGroup.Freeze(); _checkerBrush = new DrawingBrush(checkerGroup); _checkerBrush.Viewport = new Rect(0, 0, 10, 10); _checkerBrush.ViewportUnits = BrushMappingMode.Absolute; _checkerBrush.TileMode = TileMode.Tile; _checkerBrush.Freeze(); }
public static DrawingImage CreateImage(PointPattern[] pointPatterns, Size size, Color color) { if (pointPatterns == null) throw new Exception("You must provide a gesture before trying to generate a thumbnail"); DrawingGroup drawingGroup = new DrawingGroup(); for (int i = 0; i < pointPatterns.Length; i++) { PathGeometry pathGeometry = new PathGeometry(); color.A = (byte)(0xFF - i * 0x55); SolidColorBrush brush = new SolidColorBrush(color); Pen drawingPen = new Pen(brush, 3 + i * 2) { StartLineCap = PenLineCap.Round, EndLineCap = PenLineCap.Round }; if (pointPatterns[i].Points == null) return null; for (int j = 0; j < pointPatterns[i].Points.Count; j++) { if (pointPatterns[i].Points[j].Count == 1) { Geometry ellipse = new EllipseGeometry(new Point(size.Width * j + size.Width / 2, size.Height / 2), drawingPen.Thickness / 2, drawingPen.Thickness / 2); pathGeometry.AddGeometry(ellipse); continue; } StreamGeometry sg = new StreamGeometry { FillRule = FillRule.EvenOdd }; using (StreamGeometryContext sgc = sg.Open()) { // Create new size object accounting for pen width Size szeAdjusted = new Size(size.Width - drawingPen.Thickness - 1, (size.Height - drawingPen.Thickness - 1)); Size scaledSize; Point[] scaledPoints = ScaleGesture(pointPatterns[i].Points[j], szeAdjusted.Width - 10, szeAdjusted.Height - 10, out scaledSize); // Define size that will mark the offset to center the gesture double iLeftOffset = (size.Width / 2) - (scaledSize.Width / 2); double iTopOffset = (size.Height / 2) - (scaledSize.Height / 2); Vector sizOffset = new Vector(iLeftOffset + j * size.Width, iTopOffset); sgc.BeginFigure(Point.Add(scaledPoints[0], sizOffset), false, false); foreach (Point p in scaledPoints) { sgc.LineTo(Point.Add(p, sizOffset), true, true); } DrawArrow(sgc, scaledPoints, sizOffset, drawingPen.Thickness); } sg.Freeze(); pathGeometry.AddGeometry(sg); } pathGeometry.Freeze(); GeometryDrawing drawing = new GeometryDrawing(null, drawingPen, pathGeometry); drawing.Freeze(); drawingGroup.Children.Add(drawing); } // myPath.Data = sg; drawingGroup.Freeze(); DrawingImage drawingImage = new DrawingImage(drawingGroup); drawingImage.Freeze(); return drawingImage; }
void Render(int points, int size) { var sw = Stopwatch.StartNew(); var r = new Random(); var pen = new Pen(Brushes.DeepPink, 2); pen.Freeze(); Trace.WriteLine("after freeze: " + sw.GetElapsedAndRestart().TotalMilliseconds); var d = new DrawingGroup(); using (var cx = d.Open()) { for (int i = 0; i < points; i++) { cx.DrawLine(pen, new Point(r.Next(0, 50), r.Next(0, 50)), new Point(r.Next(0, 50), r.Next(0, 50))); } } d.Freeze(); var dv = new DrawingVisual(); using (var cx = dv.RenderOpen()) { cx.DrawDrawing(d); //for (int i = 0; i < points; i++) //{ // cx.DrawLine(pen, new Point(r.Next(0, 50), r.Next(0, 50)), new Point(r.Next(0, 50), r.Next(0, 50))); //} } Trace.WriteLine("after draw: " + sw.GetElapsedAndRestart().TotalMilliseconds); var trb = new RenderTargetBitmap(size, size, 96, 96, PixelFormats.Pbgra32); trb.Render(dv); Trace.WriteLine("after render: " + sw.GetElapsedAndRestart().TotalMilliseconds); var x = trb.GetPixels(); Trace.WriteLine("after get pixels: " + sw.GetElapsedAndRestart().TotalMilliseconds); //trb.Save($@"C:\temp\shit\{size}.png"); }
private void pingTimer_Tick(object sender, EventArgs e) { if (pingAnimationPhase == 6) { pingTimer.IsEnabled = false; if (menuShowGrid.IsChecked) { gridBox.Source = new BitmapImage(new Uri(@"pack://*****:*****@"pack://application:,,,/Resources/grid.png", UriKind.Absolute)); } else { img = new BitmapImage(new Uri(@"pack://application:,,,/Resources/clearTactics.png", UriKind.Absolute)); } Pen pen = new Pen(new SolidColorBrush(Color.FromArgb(pingAnimationAlpha, 255, 102, 0)), 4); Point p1 = new Point(pingArea.Key * img.PixelWidth / 10, pingArea.Value * img.PixelWidth / 10); Point p2 = new Point((pingArea.Key + 1) * img.PixelWidth / 10 + 1, pingArea.Value * img.PixelWidth / 10); Point p3 = new Point((pingArea.Key + 1) * img.PixelWidth / 10 + 1, (pingArea.Value + 1) * img.PixelWidth / 10 + 1); Point p4 = new Point(pingArea.Key * img.PixelWidth / 10, (pingArea.Value + 1) * img.PixelWidth / 10 + 1); DrawingGroup drawing = new DrawingGroup(); drawing.Children.Add(new ImageDrawing(img, new Rect(0, 0, img.PixelWidth, img.PixelHeight))); drawing.Children.Add(new GeometryDrawing(pen.Brush, pen, new LineGeometry(p1, p2))); drawing.Children.Add(new GeometryDrawing(pen.Brush, pen, new LineGeometry(p2, p3))); drawing.Children.Add(new GeometryDrawing(pen.Brush, pen, new LineGeometry(p3, p4))); drawing.Children.Add(new GeometryDrawing(pen.Brush, pen, new LineGeometry(p4, p1))); drawing.ClipGeometry = new RectangleGeometry(new Rect(0, 0, img.PixelWidth, img.PixelHeight)); drawing.Freeze(); gridBox.Source = new DrawingImage(drawing); }
private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { if (isRecording) { DateTime Time = DateTime.Now; Skeleton[] skeletons = new Skeleton[0]; float[] floor = new float[4]; using (Microsoft.Kinect.SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo(skeletons); floor[0] = skeletonFrame.FloorClipPlane.Item1; floor[1] = skeletonFrame.FloorClipPlane.Item2; floor[2] = skeletonFrame.FloorClipPlane.Item3; floor[3] = skeletonFrame.FloorClipPlane.Item4; } } foreach (Skeleton skel in skeletons) { if (skel.TrackingState == SkeletonTrackingState.Tracked) { KinectLib.SkeletonFrame frame = new KinectLib.SkeletonFrame(); frame.Date = Time; frame.SkeletonId = skel.TrackingId; frame.Nodes = new List<SkeletonNode>(); frame.X = skel.Position.X; frame.Y = skel.Position.Y; frame.Z = skel.Position.Z; frame.Floor = floor; foreach (Joint joint in skel.Joints) { SkeletonNode node = new SkeletonNode(); node.NodeType = (int)joint.JointType; node.X = joint.Position.X; node.Y = joint.Position.Y; node.Z = joint.Position.Z; frame.Nodes.Add(node); } Frames.Add(frame); Skeleton DisplaySkeleton = skel; Joint Crotch = DisplaySkeleton.Joints.First(j => j.JointType == JointType.HipCenter); if (Crotch != null) { DrawingGroup DrawingGroup = new DrawingGroup(); using (DrawingContext Context = DrawingGroup.Open()) { Double CrotchDisplayX = image1.Width / 2; Double CrotchDisplayY = image1.Height / 2; foreach (Joint Node in DisplaySkeleton.Joints) { double X = (Node.Position.X - Crotch.Position.X) / 2.5 * image1.Width + CrotchDisplayX; double Y = (-Node.Position.Y + Crotch.Position.Y) / 2.5 * image1.Height + CrotchDisplayY; Context.DrawEllipse(Brushes.Wheat, new Pen(Brushes.Navy, 2), new Point(X, Y), 7, 7); } } DrawingGroup.Freeze(); Dispatcher.Invoke(new Action(() => { image1.Source = new DrawingImage(DrawingGroup); })); } } } } }
public override ImageSource getTacticAt(int time) { DrawingGroup resultDraw = new DrawingGroup(); DrawingContext dc = resultDraw.Open(); resultDraw.ClipGeometry = new RectangleGeometry(new Rect(0, 0, clearTactic.PixelWidth, clearTactic.PixelHeight)); dc.DrawImage(clearTactic, new Rect(0, 0, clearTactic.PixelWidth, clearTactic.PixelHeight)); Pen pen = new Pen(brush, iconsSize / 2); Pen linePen = new Pen(brush, iconsSize / 25); foreach (StaticIcon staticon in staticIcons) { BitmapImage icon = staticon.getImage(); dc.DrawImage(icon, new Rect(staticon.position.X - iconsSize / 2, staticon.position.Y - iconsSize / 2, iconsSize, (iconsSize * icon.Height) / icon.Width)); if (selectedStaticIcon.Contains(staticon)) { dc.DrawGeometry(brush, linePen, makeRectangleGeometry(new Rect(staticon.position.X - iconsSize / 2 - 2, staticon.position.Y - iconsSize / 2 - 2, iconsSize + 2, (iconsSize * icon.Height) / icon.Width + 2))); } } foreach (DynamicTank tank in dynamicTanks) { BitmapSource icon; Point pos = getTankPosition(tank, time); double iconWidth = 0, iconHeight = 0; if (TankIcon == DisplayTankIcon.tanktype) { if (tank.killTime < time) { icon = icons.getTankIcon(tank.tank.type, tank.isAlly).getAliveImage(); } else { icon = icons.getTankIcon(tank.tank.type, tank.isAlly).getDeadImage(); } int roundTime = (int)(Math.Ceiling((float)time / 30.0) * 30.0); BitmapSource actionIcon = null; if (tank.actions.ContainsKey(roundTime)) { actionIcon = icons.getDynamicIcon(tank.actions[roundTime]).getImage(); } if (icon.Height < icon.Width) { iconWidth = iconsSize; iconHeight = (iconsSize * icon.Height) / icon.Width; } else { iconWidth = (iconsSize * icon.Width) / icon.Height; iconHeight = iconsSize; } dc.DrawImage(icon, new Rect(pos.X - iconWidth / 2, pos.Y - iconHeight / 2, iconWidth, iconHeight)); if (selectedDynamicTank.Contains(tank)) { dc.DrawGeometry(brush, linePen, makeRectangleGeometry(new Rect(pos.X - iconWidth / 2 - 2, pos.Y - iconHeight / 2 - 2, iconWidth + 2, iconHeight + 2))); } if (actionIcon != null) { dc.DrawImage(actionIcon, new Rect(pos.X - iconsSize, pos.Y - iconsSize, iconsSize * 2, (iconsSize * actionIcon.Height * 2) / actionIcon.Width)); } } else { if (tank.killTime < time) { icon = tank.tank.getImage(); if (icon.Height < icon.Width) { iconWidth = iconsSize * 1.8; iconHeight = (iconsSize * icon.Height) / icon.Width * 1.8; } else { iconWidth = (iconsSize * icon.Width) / icon.Height; iconHeight = iconsSize; } dc.DrawImage(icon, new Rect(pos.X - iconWidth / 2, pos.Y - iconHeight / 2, iconWidth, iconHeight)); if (selectedDynamicTank.Contains(tank)) { dc.DrawGeometry(brush, linePen, makeRectangleGeometry(new Rect(pos.X - iconWidth / 2 - 2, pos.Y - iconHeight / 2 - 2, iconWidth + 2, iconHeight + 2))); } } } if ((ShowPlayerName && tank.name != "") || ShowTankName) { string text = ""; if ((ShowPlayerName && tank.name != "") && ShowTankName) { text = tank.name + " (" + tank.tank.name + ")"; } else if (ShowPlayerName && tank.name != "") { text = tank.name; } else if (ShowTankName) { text = tank.tank.name; } FormattedText ftxt = new FormattedText(text, System.Globalization.CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface(new FontFamily("Tahoma"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal), iconsSize / 2, brush); dc.DrawText(ftxt, new Point(pos.X - ftxt.WidthIncludingTrailingWhitespace / 2 - 5, pos.Y + iconHeight / 2)); } } dc.Close(); resultDraw.Freeze(); return new DrawingImage(resultDraw); }
private void cbSkeleton_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { if (Initialized == false) return; if ((sender as ComboBox).SelectedValue == null) { (sender as ComboBox).SelectedIndex = 0; } dpMovieButtons.Visibility = Visibility.Hidden; Movie.Stop(); CurrentFrame = 0; MovieFrames.Clear(); Int32 SkeletonID = (Int32)(sender as ComboBox).SelectedValue; BackgroundWorker BgWorker = new BackgroundWorker(); BgWorker.WorkerReportsProgress = true; BgWorker.DoWork += (s, a) => { Pen SkeletonPen = new Pen(OUTLINE, 2); foreach (SkeletonFrame Frame in Frames.Where(f => f.SkeletonId == SkeletonID)) { (s as BackgroundWorker).ReportProgress(0, "Frames loading " + Convert.ToString(Frames.IndexOf(Frame) + 1) + "/" + Convert.ToString(Frames.Count)); NodesNormalizer NodesNormalizer = new NodesNormalizer(Frame.Nodes); DrawingGroup DrawingGroup = new DrawingGroup(); using (DrawingContext Context = DrawingGroup.Open()) { Context.DrawRectangle(Brushes.Transparent, new Pen(Brushes.Transparent, 0), new Rect(0, 0, WIDTH, HEIGHT)); Double CrotchDisplayX = WIDTH / 2; Double CrotchDisplayY = 20; SkeletonNode Crotch = Frame.Nodes.FirstOrDefault(n => n.NodeType == 0); if (Crotch != null) { foreach (SkeletonNode Node in NodesNormalizer.NormalizedNodes) { Context.DrawEllipse(NODE_COLOR, SkeletonPen, new Point(Node.X * RESOLUTION + CrotchDisplayX, Node.Y * RESOLUTION + CrotchDisplayY), NODE_RADIUS, NODE_RADIUS); } } } DrawingGroup.Freeze(); MovieFrames.Add(DrawingGroup); } }; BgWorker.ProgressChanged += (s, a) => { lbStatus.Content = a.UserState; }; BgWorker.RunWorkerCompleted += (s, a) => { //Show first skeleton frame imSkeleton.Source = new DrawingImage(MovieFrames.ElementAt(0)); //Switch on movie buttons dpMovieButtons.Visibility = Visibility.Visible; lbStatus.Content = "File successfully loaded"; }; BgWorker.RunWorkerAsync(); }
private void InsertPictureLayer (DataRow PictureRow, DrawingGroup FramingGroup, DataRow ConnectPicturesRow, double OriginalWidth, double OriginalHeight, String LocalWPMediaRoot, DataTable MaterialTable) { System.Windows.Point StartingPoint = new System.Windows.Point ((Convert.ToInt32 (PictureRow ["PositionLeft"]) * OriginalWidth) / 100, (Convert.ToInt32 (PictureRow ["PositionTop"]) * OriginalHeight) / 100); bool FixPositioned = false; if (ConnectPicturesRow ["PositionedByFileName"] != null) if (ConnectPicturesRow ["PositionedByFileName"].ToString () == "Yes") { StartingPoint.X = (Convert.ToInt32 (ConnectPicturesRow ["XPositioningPercentage"]) * OriginalWidth) / 100; StartingPoint.Y = (Convert.ToInt32 (ConnectPicturesRow ["YPositioningPercentage"]) * OriginalHeight) / 100; FixPositioned = true; } String PhysicalFileName = ConnectPicturesRow ["PictureFileName"].ToString (); Stream PictureSource = null; if (MaterialTable != null) { DataRow [] Materials = MaterialTable.Select ("NameID = '" + PhysicalFileName + "'"); if (Materials.Length != 1) return; PictureSource = new MemoryStream (Materials [0] ["MaterialByteArray"] as Byte []); } else { if (!Path.IsPathRooted (PhysicalFileName)) PhysicalFileName = Path.Combine (LocalWPMediaRoot, PhysicalFileName); if (String.IsNullOrEmpty (PhysicalFileName)) return; if (!File.Exists (PhysicalFileName)) return; PictureSource = new FileStream (PhysicalFileName, FileMode.Open, FileAccess.Read); } DrawingGroup PictureDrawingGroup = new DrawingGroup (); BitmapImage PicturePart = new BitmapImage (); PicturePart.BeginInit (); PicturePart.CacheOption = BitmapCacheOption.OnLoad; PicturePart.StreamSource = PictureSource; PicturePart.EndInit (); PictureSource.Close (); PictureSource.Dispose (); double RealWidth = PicturePart.PixelWidth; double RealHeight = PicturePart.PixelHeight; double RealAspectRatio = RealWidth / RealHeight; double MeasuredWidth = PicturePart.Width; double MeasuredHeight = PicturePart.Height; double PositionLeft = Convert.ToDouble (PictureRow ["PositionLeft"]); double PositionTop = Convert.ToDouble (PictureRow ["PositionTop"]); double PositionRight = Convert.ToDouble (PictureRow ["PositionRight"]); double PositionBottom = Convert.ToDouble (PictureRow ["PositionBottom"]); double TargetWidth = ((PositionRight - PositionLeft) * OriginalWidth) / 100; double TargetHeight = ((PositionBottom - PositionTop) * OriginalHeight) / 100; double PositioningFactor = 1; if (!FixPositioned) { double FramingAspectRatio = TargetWidth/TargetHeight; if (FramingAspectRatio >= RealAspectRatio) { RealHeight = TargetHeight; RealWidth = RealHeight * RealAspectRatio; } else { RealWidth = TargetWidth; RealHeight = RealWidth / RealAspectRatio; } } System.Windows.Point DrawingStartingPoint = StartingPoint; System.Windows.Size DrawingSize = new System.Windows.Size (RealWidth, RealHeight); double TargetAspectRatio = DrawingSize.Width / DrawingSize.Height; if (TargetAspectRatio >= RealAspectRatio) { DrawingSize.Width = DrawingSize.Height*RealAspectRatio; if (!FixPositioned) { DrawingStartingPoint.X += (TargetWidth - DrawingSize.Width) / 2; } else { } } else { DrawingSize.Height = DrawingSize.Width / RealAspectRatio; if (!FixPositioned) { DrawingStartingPoint.Y += (TargetHeight - DrawingSize.Height) / 2; } else { } } ImageDrawing PositionableEntry = new ImageDrawing(); PositionableEntry.ImageSource = PicturePart; ; PositionableEntry.Rect = new Rect (DrawingStartingPoint, DrawingSize); PictureDrawingGroup.Children.Add (PositionableEntry); PictureDrawingGroup.Opacity = Convert.ToDouble (PictureRow ["Transparency"])/100; FramingGroup.Children.Add (PictureDrawingGroup); PictureDrawingGroup.Freeze (); InsertDisposeableElement (PositionableEntry); InsertDisposeableElement (PictureDrawingGroup); InsertDisposeableElement (PicturePart); }
private void bnLoad_Click(object sender, RoutedEventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); InitMovieFrames(); if (dlg.ShowDialog() == true) { lbStatus.Content = "Please wait. File loading..."; Dictionary<Int32, String> Items = new Dictionary<Int32, String>(); BackgroundWorker BgWorker = new BackgroundWorker(); BgWorker.WorkerReportsProgress = true; BgWorker.DoWork += (s, a) => { //Load Frames using (FileStream writer = File.OpenRead(dlg.FileName)) { IFormatter formatter = new BinaryFormatter(); Frames = formatter.Deserialize(writer) as List<KinectLib.SkeletonFrame>; } //Set up skeletons Byte Index = 0; foreach (Int32 SkeletonID in Frames.Select(f => f.SkeletonId).Distinct()) { Items.Add(SkeletonID, "Skeleton " + Convert.ToString(++Index)); } //Parse Frames String Lengths = ""; PathDetector PathDetector = new PathDetector(Frames.Where(f => f.SkeletonId == Frames.First().SkeletonId).ToList()); Pen SkeletonPen = new Pen(OUTLINE, 2); foreach (SkeletonFrame Frame in Frames.Where(f => f.SkeletonId == Frames.First().SkeletonId)) { (s as BackgroundWorker).ReportProgress(0, "Frames loading " + Convert.ToString(Frames.IndexOf(Frame) + 1) + "/" + Convert.ToString(Frames.Count)); //String ss = String.Empty; //foreach (SkeletonNode Node in Frame.Nodes) //{ // ss += String.Format("{0};{1};{2};{3}\n", Node.NodeType, Node.X, Node.Y, Node.Z); //} NodesNormalizer NodesNormalizer = new NodesNormalizer(Frame.Nodes); //SkeletonBone b1 = new SkeletonBone(Nodes.First(n => n.NodeType == 0), Nodes.First(n => n.NodeType == 12)); //SkeletonBone b2 = new SkeletonBone(Nodes.First(n => n.NodeType == 0), Nodes.First(n => n.NodeType == 16)); //Lengths += String.Format("{0} {1}\n", b1.Length,b2.Length); Lengths += String.Format("{0} {1} {2};\n", Frame.X, Frame.Y, Frame.Z); DrawingGroup DrawingGroup = new DrawingGroup(); using (DrawingContext Context = DrawingGroup.Open()) { Context.DrawRectangle(Brushes.Transparent, new Pen(Brushes.Transparent, 0), new Rect(0, 0, WIDTH, HEIGHT)); Double CrotchDisplayX = WIDTH / 2; Double CrotchDisplayY = 20; SkeletonNode Crotch = Frame.Nodes.FirstOrDefault(n => n.NodeType == 0); if (Crotch != null) { foreach (SkeletonNode Node in NodesNormalizer.NormalizedNodes) { Context.DrawEllipse(NODE_COLOR, SkeletonPen, new Point(Node.X * RESOLUTION + CrotchDisplayX, Node.Y * RESOLUTION + CrotchDisplayY), NODE_RADIUS, NODE_RADIUS); } } } DrawingGroup.Freeze(); MovieFrames.Add(DrawingGroup); } double x = 0; }; BgWorker.ProgressChanged += (s, a) => { lbStatus.Content = a.UserState; }; BgWorker.RunWorkerCompleted += (s, a) => { //Set up Window title String[] FileParts = dlg.FileName.Split(@"\".ToCharArray()); Title = FileParts[FileParts.Length - 1] + " - KinectPlayer"; //Set up skeletons cbSkeleton.ItemsSource = Items; cbSkeleton.SelectedIndex = 0; cbSkeleton.Visibility = Visibility.Visible; //Show first skeleton frame imSkeleton.Source = new DrawingImage(MovieFrames.ElementAt(0)); //Switch on movie buttons dpMovieButtons.Visibility = Visibility.Visible; lbStatus.Content = "File successfully loaded"; Initialized = true; }; BgWorker.RunWorkerAsync(); } }
private void DrawTiles(System.Windows.Media.DrawingContext dc) { TilesWideObject = (int)(this.ActualWidth / 4) + 1; TilesHighObject = (int)(this.ActualHeight / 4) + 1; int startX = (int)CurrentPointObject.X - (TilesWideObject / 2); int startY = (int)CurrentPointObject.Y - (TilesHighObject / 2); if (startX < 0) startX = 0; if (startY < 0) startY = 0; int endX = startX + TilesWideObject; int endY = startY + TilesHighObject; if (endX > GameWorldObject.GameMapWidth) { endX = GameWorldObject.GameMapWidth; startX = endX - TilesWideObject; } else if (startX < 0) { startX = 0; endX = TilesWideObject; } if (endY > GameWorldObject.GameMapHeight) { endY = GameWorldObject.GameMapHeight; startY = endY - TilesHighObject; } else if (startY < 0) { startY = 0; endY = TilesHighObject; } int CountX = 0; int CountY = 0; DrawingGroup dg = new DrawingGroup(); for (int x = startX; x < endX; x++) { for (int y = startY; y < endY; y++) { dg.Children.Add( new ImageDrawing(_mapTiles[GameWorldObject.GameMap[x, y].GraphicsTile.TileStartPoint], new Rect(CountX * 4, CountY * 4, 4, 4) )); dg.Children.Add( new GeometryDrawing( null, new Pen( new SolidColorBrush( Color.FromRgb(255, 0, 20)), .1), new RectangleGeometry( new Rect(CountX * 4, CountY * 4, 4, 4) ) ) ); CountY++; } CountY = 0; CountX++; } dg.Freeze(); dc.DrawDrawing(dg); //dc.DrawDrawing(DrawMainMapLocation()) }
private void DrawGrid(DrawingContext dc, CanvasData canvas, int gridLineFrequency) { StaticDrawing sd; if (!Drawings.Static.TryGetValue("Grid", out sd)) { var drawing = new DrawingGroup(); using (var groupdc = drawing.Open()) { // vertical lines int pos = 0; do { groupdc.DrawLine(RadarBrushes.GridPen, new Point(pos, 0), new Point(pos, (int) canvas.CanvasSize.Height)); pos += (int) canvas.GridSquareSize.Height*gridLineFrequency; } while (pos < canvas.CanvasSize.Width); // horizontal lines pos = 0; do { groupdc.DrawLine(RadarBrushes.GridPen, new Point(0, pos), new Point((int) canvas.CanvasSize.Width, pos)); pos += (int) canvas.GridSquareSize.Width*gridLineFrequency; } while (pos < canvas.CanvasSize.Height); } drawing.Freeze(); Drawings.Static.TryAdd("Grid", new StaticDrawing { Drawing = drawing, WorldId = CacheManager.WorldDynamicId }); } else { dc.DrawDrawing(sd.Drawing); } }
/// <summary> /// Creates a colour swatch image with background and border /// </summary> /// <param name="colourPos">Position in the test where the colour, and what colour it is.</param> /// <param name="charSpan">Text that the image will go above</param> private Image CreateSwatchImage(Tuple<int, int, Color> colourPos, SnapshotSpan charSpan) { IWpfTextViewLineCollection textViewLines = _view.TextViewLines; Geometry g = textViewLines.GetMarkerGeometry(charSpan); Rect r = new Rect(5, 5, 30, 30); RectangleGeometry rg = new RectangleGeometry(r); Brush brush = new SolidColorBrush(colourPos.Item3); brush.Freeze(); Brush penBrush = new SolidColorBrush(colourPos.Item3); penBrush.Freeze(); Pen pen = new Pen(penBrush, 0.5); pen.Freeze(); GeometryDrawing drawingfront = new GeometryDrawing(brush, pen, rg); drawingfront.Freeze(); Brush penBrushBorder = new SolidColorBrush(Color.FromRgb(0xad, 0xad, 0xad)); penBrushBorder.Freeze(); Pen penBorder = new Pen(penBrushBorder, 0.5); penBorder.Freeze(); Rect rWhite = new Rect(0, 0, 20, 40); RectangleGeometry rgWhite = new RectangleGeometry(rWhite); Brush brushWhite = new SolidColorBrush(Color.FromRgb(255, 255, 255)); brushWhite.Freeze(); GeometryDrawing drawingleft = new GeometryDrawing(brushWhite, penBorder, rgWhite); drawingleft.Freeze(); Rect rBlack = new Rect(20, 0, 20, 40); RectangleGeometry rgBlack = new RectangleGeometry(rBlack); Brush brushBlack = new SolidColorBrush(Color.FromRgb(0, 0, 0)); brushBlack.Freeze(); GeometryDrawing drawingright = new GeometryDrawing(brushBlack, penBorder, rgBlack); drawingright.Freeze(); DrawingGroup drawing = new DrawingGroup(); drawing.Children.Add(drawingleft); drawing.Children.Add(drawingright); drawing.Children.Add(drawingfront); drawing.Freeze(); DrawingImage drawingImage = new DrawingImage(drawing); drawingImage.Freeze(); Image image = new Image(); image.Source = drawingImage; Canvas.SetLeft(image, g.Bounds.Left - g.Bounds.Width); Canvas.SetTop(image, g.Bounds.Top - 40); return image; }
public BitmapSource getMapImage() { if (mapImg == null) { if (_mapPack == MapPack.Original) { mapImg = new BitmapImage(new Uri(originalFilename, UriKind.RelativeOrAbsolute)); } else { mapImg = new BitmapImage(new Uri(hdFilename, UriKind.RelativeOrAbsolute)); } if (_type != BattleType.Undefined) { DrawingGroup group = new DrawingGroup(); group.Children.Add(new ImageDrawing(mapImg, new Rect(0, 0, mapImg.PixelWidth, mapImg.PixelHeight))); for (int i = 0; i < presets.Length; i++) { if (presets[i].battle == _type && presets[i].variation == _variation) { BitmapImage icon = presets[i].icon.getImage(); group.Children.Add(new ImageDrawing(icon, new Rect(presets[i].icon.position.X - _iconsSize / 2, presets[i].icon.position.Y - _iconsSize / 2, _iconsSize, (_iconsSize * icon.Height) / icon.Width))); } } group.ClipGeometry = new RectangleGeometry(new Rect(0, 0, mapImg.PixelWidth, mapImg.PixelHeight)); group.Freeze(); var image = new Image { Source = new DrawingImage(group) }; var bitmap = new RenderTargetBitmap(mapImg.PixelWidth, mapImg.PixelHeight, 96, 96, PixelFormats.Pbgra32); image.Arrange(new Rect(0, 0, mapImg.PixelWidth, mapImg.PixelHeight)); bitmap.Render(image); mapImg = BitmapFactory.ConvertToPbgra32Format(bitmap); } } return (BitmapSource)mapImg.Clone(); }