private void UpdateBrushImage(PaddedBrushModel brushModel)
        {
            using (DrawingContext context = this.selectedBrushImage.Open())
            {
                foreach (Tile tile in brushModel.Tiles)
                {
                    context.DrawDrawing(tile.Image.Value);
                }
            }
            this.gridModel.Columns    = brushModel.Columns;
            this.gridModel.Rows       = brushModel.Rows;
            this.gridModel.TileWidth  = brushModel.TileWidth;
            this.gridModel.TileHeight = brushModel.TileHeight;

            this.imageTransform.SetPixelToTile(this.gridModel.TileWidth.Value, this.gridModel.TileHeight.Value);
            this.imageTransform.SetSelectionToPixel(this.gridModel.TileWidth.Value / 2, this.gridModel.TileHeight.Value / 2);

            redrawExtendedBackground();
            RedrawGrid();
        }
Beispiel #2
0
        private void buttonUndo_Click(object sender, RoutedEventArgs e)
        {
            ptinfos.Clear();             // REM 清除一笔中所有点
            CreateNewBitmap();

            if ((geos.Count > 0))
            {
                strokes.RemoveAt(strokes.Count - 1);           // REM 清除上一笔

                geos.RemoveAt(geos.Count - 1);                 // REM 清除上一笔
                DrawingContext dc = dv.RenderOpen();
                foreach (var g in geos)
                {
                    GeometryDrawing drawing = new GeometryDrawing(Brushes.Black, new Pen(Brushes.Black, 1), g);
                    dc.DrawDrawing(drawing);
                }
                dc.Close();
                bmp.Render(dv);
            }
        }
        public void ChangeItemModel(TilesetModel tilesetModel)
        {
            if (tilesetModel == null)
            {
                return;
            }
            if (!this.TilesetModels.Contains(tilesetModel))
            {
                return;
            }
            this.IsSourceLoaded.Value                = true;
            this.TilesetModel.Value                  = tilesetModel;
            this.TilesetModel.Value.IsTransparent    = tilesetModel.IsTransparent;
            this.TilesetModel.Value.TransparentColor = tilesetModel.TransparentColor;
            this.Session.CurrentTileset.Value        = this.TilesetModel.Value;
            this.ItemImage.Value = CvInvoke.Imread(this.TilesetModel.Value.SourcePath.Value, Emgu.CV.CvEnum.ImreadModes.Unchanged);

            this.itemTransform = new CoordinateTransform();
            this.itemTransform.SetPixelToTile(this.TilesetModel.Value.TileWidth.Value, this.TilesetModel.Value.TileHeight.Value);
            this.itemTransform.SetSelectionToPixel(this.TilesetModel.Value.TileWidth.Value / 2, this.TilesetModel.Value.TileHeight.Value / 2);

            this.TilesetModel.Value.IsTransparent.PropertyChanged += IsTransparentChanged;

            Mat drawingMat = this.ItemImage.Value;

            if (this.TilesetModel.Value.IsTransparent.Value)
            {
                drawingMat = ImageUtils.ColorToTransparent(this.ItemImage.Value, this.TilesetModel.Value.TransparentColor.Value);
            }

            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                using (DrawingContext context = this.tilesetImage.Open())
                {
                    context.DrawDrawing(ImageUtils.MatToImageDrawing(drawingMat));
                }
            }), DispatcherPriority.Render);

            RedrawBackground();
            RedrawGrid();
        }
Beispiel #4
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            if (_markPen == null)
            {
                _devicePixelUnit = DpiUtil.GetDevicePixelUnit(this);
                _markPen         = new Pen(new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF7F7F7F")), 1.0 / _devicePixelUnit);
                _markPen.Freeze();
            }

            if (_baselinePen == null)
            {
                _devicePixelUnit = DpiUtil.GetDevicePixelUnit(this);
                _baselinePen     = new Pen(Brushes.Black, 1.0 / _devicePixelUnit);
                _baselinePen.Freeze();
            }

            Render();
            drawingContext.DrawDrawing(_drawingGroup);
        }
Beispiel #5
0
        /// <summary>
        /// <code>DrawingVisual</code>に設定されている<code>Drawing</code>インスタンス全てのアンチエイリアスを解除する
        /// </summary>
        /// <param name="dv"><code>DwawingVisual</code></param>
        /// <returns>アンチエイリアスを解除した<code>DrawingVisual</code></returns>
        internal static DrawingVisual SetRenderOptions(DrawingVisual dv)
        {
            var drawingGroup = dv.Drawing;

            foreach (var d in GetDrawings(drawingGroup))
            {
                if (!d.IsSealed)
                {
                    RenderOptions.SetBitmapScalingMode(d, BitmapScalingMode.Fant);
                    RenderOptions.SetEdgeMode(d, EdgeMode.Aliased);
                }
            }

            dv = new DrawingVisual();
            using (DrawingContext ctx = dv.RenderOpen())
            {
                ctx.DrawDrawing(drawingGroup);
            }

            return(dv);
        }
Beispiel #6
0
        public ImageSource ScaleLogicalImageForDeviceSize(ImageSource image, System.Windows.Size deviceImageSize, BitmapScalingMode scalingMode)
        {
            Validate.IsNotNull(image, "image");
            DrawingGroup drawingGroup = new DrawingGroup();

            drawingGroup.Children.Add(new ImageDrawing(image, new Rect(deviceImageSize)));
            DrawingVisual drawingVisual = new DrawingVisual();

            using (DrawingContext drawingContext = drawingVisual.RenderOpen())
            {
                RenderOptions.SetBitmapScalingMode(drawingGroup, scalingMode);
                drawingContext.DrawDrawing(drawingGroup);
            }
            RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap((int)deviceImageSize.Width, (int)deviceImageSize.Height, LogicalDpiX, LogicalDpiY, PixelFormats.Default);

            renderTargetBitmap.Render(drawingVisual);
            BitmapFrame bitmapFrame = BitmapFrame.Create(renderTargetBitmap);

            bitmapFrame.Freeze();
            return(bitmapFrame);
        }
Beispiel #7
0
        /// <summary>
        /// Render the generated Drawings.
        /// </summary>
        /// <param name="drawingContext">DrawingContext parameter</param>
        protected override void OnRender(DrawingContext drawingContext)
        {
            if (this.logic != null && this.ActualWidth != 0)
            {
                if (!this.logic.IsGameEnded)
                {
                    if (this.logic.IsGamePaused)
                    {
                        FormattedText f = new FormattedText($"{this.GameModel.Player1.NumberOfWins} - {this.GameModel.Player2.NumberOfWins}", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 120, Brushes.White);

                        drawingContext.DrawRectangle(Brushes.Black, null, new Rect(0, 0, this.ActualWidth, this.ActualHeight));
                        drawingContext.DrawText(f, new Point((this.ActualWidth - f.Width) / 2, (this.ActualHeight - f.Height) / 2));
                    }
                    else
                    {
                        drawingContext.DrawDrawing(this.display.GetDrawings());
                    }
                }
                else
                {
                    FormattedText endText = new FormattedText($"Játék vége.", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 100, Brushes.White);
                    FormattedText resText = new FormattedText($"{this.GameModel.Player1.NumberOfWins} - {this.GameModel.Player2.NumberOfWins}", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 72, Brushes.White);
                    FormattedText winText;

                    if (this.GameModel.Player1.NumberOfWins == 5)
                    {
                        winText = new FormattedText($"Gőztes: {this.GameModel.Player1.Name}", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 50, Brushes.White);
                    }
                    else
                    {
                        winText = new FormattedText($"Gőztes: {this.GameModel.Player2.Name}", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 50, Brushes.White);
                    }

                    drawingContext.DrawRectangle(Brushes.Black, null, new Rect(0, 0, this.ActualWidth, this.ActualHeight));
                    drawingContext.DrawText(endText, new Point((this.ActualWidth - endText.Width) / 2, ((this.ActualHeight - endText.Height) / 2) - 100));
                    drawingContext.DrawText(resText, new Point((this.ActualWidth - resText.Width) / 2, (this.ActualHeight - resText.Height) / 2));
                    drawingContext.DrawText(winText, new Point((this.ActualWidth - winText.Width) / 2, ((this.ActualHeight - winText.Height) / 2) + 100));
                }
            }
        }
        private bool SaveImageFile(Drawing drawing, Stream imageStream)
        {
            BitmapEncoder bitmapEncoder = this.GetBitmapEncoder(
                this.GetImageFileExtention());

            // The image parameters...
            //Rect drawingBounds = drawing.Bounds;
            //int pixelWidth  = (int)drawingBounds.Width;
            //int pixelHeight = (int)drawingBounds.Height;
            double dpiX = 96;
            double dpiY = 96;

            // The Visual to use as the source of the RenderTargetBitmap.
            DrawingVisual  drawingVisual  = new DrawingVisual();
            DrawingContext drawingContext = drawingVisual.RenderOpen();

            if (this.Background != null)
            {
                drawingContext.DrawRectangle(this.Background, null, drawing.Bounds);
            }
            drawingContext.DrawDrawing(drawing);
            drawingContext.Close();

            /// get bound of the visual
            Rect drawingBounds = VisualTreeHelper.GetDescendantBounds(drawingVisual);
            int  pixelWidth    = (int)drawingBounds.Width;
            int  pixelHeight   = (int)drawingBounds.Height;

            // The BitmapSource that is rendered with a Visual.
            RenderTargetBitmap targetBitmap = new RenderTargetBitmap(
                pixelWidth, pixelHeight, dpiX, dpiY, PixelFormats.Pbgra32);

            targetBitmap.Render(drawingVisual);

            // Encoding the RenderBitmapTarget as an image file.
            bitmapEncoder.Frames.Add(BitmapFrame.Create(targetBitmap));
            bitmapEncoder.Save(imageStream);

            return(true);
        }
Beispiel #9
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            var clock      = GetAnimationClock(this);
            var step       = (int)Math.Floor(clock * Spokes);
            var halfWidth  = ActualWidth / 2;
            var halfHeight = ActualHeight / 2;
            var scale      = Math.Min(halfWidth, halfHeight);

            var matrix = Matrix.Identity;

            matrix.Scale(scale, scale);
            var angle = -(step * 360.0) / Spokes;

            matrix.Rotate(angle);
            matrix.Translate(halfWidth, halfHeight);

            drawingContext.PushTransform(new MatrixTransform(matrix));

            drawingContext.DrawDrawing(s_drawing);

            drawingContext.Pop();
        }
Beispiel #10
0
        public void Display(DrawingContext context)
        {
            DrawingGroup dg = new DrawingGroup();

            // Background
            dg.Children.Add(new GeometryDrawing(Settings.BackgroundColor, new Pen(Settings.FrameColor, Settings.FrameSize),
                                                new RectangleGeometry(new Rect(0, 0, Settings.WindowWidth - Settings.FrameSize * 4, Settings.WindowHeight - Settings.FrameSize * 2))
                                                ));

            // Projectiles
            foreach (Projectile projectile in gameModel.Projectiles)
            {
                dg.Children.Add(new GeometryDrawing(Settings.ProjectileColor, new Pen(Settings.ProjectileColor, 1), projectile.Shape()));
            }

            // Scores
            FormattedText text = new FormattedText(gameModel.Score.ToString(),
                                                   System.Globalization.CultureInfo.CurrentCulture,
                                                   FlowDirection.LeftToRight,
                                                   new Typeface("Comic-Sans"),
                                                   15,
                                                   Brushes.White,
                                                   VisualTreeHelper.GetDpi(new GameControl()).PixelsPerDip);

            dg.Children.Add(new GeometryDrawing(null, new Pen(Brushes.White, 1), text.BuildGeometry(new Point(10, 5))));

            context.DrawDrawing(dg);
            DrawSpacship(context);
            DrawUFO(context);
            DrawShield(context);

            // Player lifes
            // position of the first Player life sprite.

            for (int i = 1; i <= gameModel.Player.HitPoint; i++)
            {
                DrawPlayerLife(context, Settings.WindowWidth - i * 20, 5);
            }
        }
Beispiel #11
0
        public override DocumentPage GetPage(int pageNumber)
        {
            int x = pageNumber % pageCountX;
            int y = pageNumber / pageCountX;

            Rect view = new Rect();

            view.X    = x * contentSize.Width;
            view.Y    = y * contentSize.Height;
            view.Size = contentSize;

            DrawingVisual v = new DrawingVisual();

            using (DrawingContext dc = v.RenderOpen())
            {
                dc.DrawRectangle(null, framePen, frameRect);
                dc.PushTransform(new TranslateTransform(margin - view.X, margin - view.Y));
                dc.PushClip(new RectangleGeometry(view));
                dc.DrawDrawing(graph);
            }
            return(new DocumentPage(v, PageSize, frameRect, frameRect));
        }
Beispiel #12
0
        public void DrawVisuals()
        {
            DrawingGroup  ghostDrawing = FindResource("ghostDrawing") as DrawingGroup;
            DrawingVisual ghostVisual  = new DrawingVisual();

            using (DrawingContext dc = ghostVisual.RenderOpen())
            {
                dc.DrawDrawing(ghostDrawing);
            }

            GeometryDrawing bodyDrawing      = FindResource("bodyDrawing") as GeometryDrawing;
            GeometryDrawing eyesDrawing      = FindResource("eyesDrawing") as GeometryDrawing;
            GeometryDrawing mouthDrawing     = FindResource("mouthDrawing") as GeometryDrawing;
            DrawingVisual   ghostVisualParts = new DrawingVisual();

            using (DrawingContext dc = ghostVisualParts.RenderOpen())
            {
                dc.DrawDrawing(bodyDrawing);
                dc.DrawDrawing(eyesDrawing);
                dc.DrawDrawing(mouthDrawing);
            }
        }
Beispiel #13
0
        private void UnlockBuffer(int width, int height, int dst_width, int dst_height)
        {
            _bufferBitmap.AddDirtyRect(new Int32Rect(0, 0, width, height));
            _bufferBitmap.Unlock();

            if (_track.CanvasWidth > 0 && _track.CanvasHeight > 0)
            {
                ImageBrush text_brush = new ImageBrush(_bufferBitmap);
                text_brush.ViewboxUnits = BrushMappingMode.Absolute;
                text_brush.Viewbox      = new Rect(0, 0, width, height);

                var drawing_group = new DrawingGroup();
                RenderOptions.SetBitmapScalingMode(drawing_group, BitmapScalingMode.HighQuality);
                var rectangle_geometry = new RectangleGeometry(new Rect(0, 0, dst_width, dst_height));
                var geometry_drawing   = new GeometryDrawing(text_brush, null, rectangle_geometry);
                drawing_group.Children.Add(geometry_drawing);

                using (DrawingContext dc = _textVisual.RenderOpen())
                {
                    dc.DrawDrawing(drawing_group);
                }

                var bmp = new RenderTargetBitmap(dst_width, (int)_track.CanvasHeight, 96, 96, PixelFormats.Pbgra32);
                bmp.Render(_textVisual);

                using (DrawingContext dc = _textVisual.RenderOpen())
                {
                    dc.DrawImage(bmp, new Rect(TextOffset, 0, bmp.Width, bmp.Height));
                }
            }

            _thread = null;

            if (_invalidateText)
            {
                _invalidateText = false;
                InvalidateText();
            }
        }
        public override void Draw()
        {
            if (topLeft == null || topRight == null || bottomLeft == null || bottomRight == null)
            {
                return;
            }

            using (DrawingContext dc = RenderOpen())
            {
                if (Status == EntityStatus.Selected)
                {
                    var d      = 10;
                    var vector = new Vector(d, d);
                    dc.PushOpacity(0.5);
                    dc.DrawRectangle(selectBrush, null, new Rect(Dimensions.TopLeft - vector, Dimensions.BottomRight + vector));
                    dc.Pop();
                }

                dc.DrawRectangle(normalBrush, normalPen, Dimensions);
                dc.DrawDrawing(DrawTitle(Position));
            }
        }
Beispiel #15
0
        private Visual GetVisual(double offsetX, double offsetY)
        {
            ContainerVisual root   = new ContainerVisual();
            DrawingVisual   visual = new DrawingVisual();

            root.Children.Add(visual);
            visual.Offset = new Vector(offsetX, offsetY);

            DrawingContext dc = visual.RenderOpen();

            dc.DrawDrawing(_page.GetDrawing());
            dc.Close();

            UIElementCollection vc = _page.Children;

            foreach (UIElement child in vc)
            {
                CloneVisualTree(visual, child);
            }

            return(root);
        }
        private void Render(bool bitmapDirty)
        {
            if (bitmapDirty)
            {
                lock (l)
                {
                    _bitmap = BitmapSource.Create(
                        _bitmapWidth,
                        _bitmapHeight,
                        96,
                        96,
                        _pixelFormat,
                        null,
                        _bitmapPixels,
                        _bitmapStride);
                }
            }

            // Render the text bitmap with scaling
            DrawingGroup drawingGroup = new DrawingGroup();

            RenderOptions.SetBitmapScalingMode(drawingGroup, BitmapScalingMode.HighQuality);              //Options, Fant?
            ImageDrawing image      = new ImageDrawing();
            double       textHeight = Math.Min(Height, _progressiveScroll.DrawHeight);

            image.Rect        = new Rect(0.0, 0.0, _progressiveScroll.ActualWidth, textHeight);
            image.ImageSource = _bitmap;
            drawingGroup.Children.Add(image);

            using (DrawingContext drawingContext = TextVisual.RenderOpen())
            {
                drawingContext.DrawDrawing((Drawing)drawingGroup);
            }

            if (_invalidateAgain)
            {
                Invalidate(Parts.TextContent);
            }
        }
        public static BitmapFrame Resize(BitmapSource image, int width, int height, BitmapScalingMode scalingMode)
        {
            DrawingGroup drawingGroup = new DrawingGroup();

            RenderOptions.SetBitmapScalingMode(drawingGroup, scalingMode);
            drawingGroup.Children.Add(new ImageDrawing(image, new Rect(0, 0, width, height)));

            DrawingVisual targetVisual = new DrawingVisual();

            DrawingContext targetContext = targetVisual.RenderOpen();

            targetContext.DrawDrawing(drawingGroup);

            RenderTargetBitmap target = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Default);

            targetContext.Close();
            target.Render(targetVisual);

            BitmapFrame targetFrame = BitmapFrame.Create(target);

            return(targetFrame);
        }
Beispiel #18
0
        public static WriteableBitmap ResizeHighQuality(this BitmapSource source, int width, int height)
        {
            Rect rect = new Rect(0, 0, width, height);

            DrawingGroup group = new DrawingGroup();

            RenderOptions.SetBitmapScalingMode(group, BitmapScalingMode.HighQuality);

            group.Children.Add(new ImageDrawing(source, rect));

            DrawingVisual visual = new DrawingVisual();

            using (DrawingContext context = visual.RenderOpen()) {
                context.DrawDrawing(group);
            }

            RenderTargetBitmap destination = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);

            destination.Render(visual);

            return(BitmapFactory.ConvertToPbgra32Format(destination));
        }
Beispiel #19
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            if (ChartData == null)
            {
                return;
            }

            if (GraphContents == null)
            {
                // ActualWidth and ActualHeight are NaN at initialization, need to do this here
                Viewport.Visible = new Rect(new Size(ActualWidth, ActualHeight));
                Viewport.OnViewportResized(ActualWidth, ActualHeight);
                GraphContents = new DrawingGroup();
            }

            if (FilteredPoints == null)
            {
                Update();
            }

            using (DrawingContext context = GraphContents.Open())
            {
                // Draw Background
                context.DrawRectangle(ChartStyle.BackgroundColor, null, Viewport.Output);

                // Draw Chart
                ChartDrawing.Draw(context, FilteredPoints, ChartStyle);

                //Draw Debug text
                context.DrawText(new FormattedText("Viewport.Visible=" + Viewport.Visible + "\n" + "Viewport.Output=" + Viewport.Output,
                                                   CultureInfo.InvariantCulture,
                                                   FlowDirection.LeftToRight,
                                                   new Typeface("Arial"), 12, Brushes.Red),
                                 new Point(10, 10));
            }

            drawingContext.DrawDrawing(GraphContents);
        }
Beispiel #20
0
        public override void Draw()
        {
            using (DrawingContext dc = RenderOpen())
            {
                var radiusX = Width / 2;
                var radiusY = Height / 2;
                var d       = 10;

                if (Status == EntityStatus.Selected)
                {
                    dc.PushOpacity(0.5);
                    dc.DrawEllipse(selectBrush, null, Position, d + radiusX, d + radiusY);
                    dc.Pop();
                }

                dc.DrawEllipse(normalBrush, normalPen, Position, radiusX, radiusY);
                if (StairsNode.IsFloorsConnected)
                {
                    var v = new Vector(Width, Height);
                }
                dc.DrawDrawing(DrawTitle(Position));
            }
        }
        static Drawing NormalizeDrawing(Drawing drawing, Point location, Size size, double angle)
        {
            DrawingGroup dGroup = new DrawingGroup();

            using (DrawingContext dc = dGroup.Open())
            {
                dc.DrawRectangle(Brushes.Transparent, null, new Rect(new Size(100, 100)));

                dc.PushTransform(new RotateTransform(angle, 50, 50));
                dc.PushTransform(new TranslateTransform(location.X, location.Y));
                dc.PushTransform(new ScaleTransform(size.Width / drawing.Bounds.Width, size.Height / drawing.Bounds.Height));
                dc.PushTransform(new TranslateTransform(-drawing.Bounds.Left, -drawing.Bounds.Top));

                dc.DrawDrawing(drawing);

                dc.Pop();
                dc.Pop();
                dc.Pop();
                dc.Pop();
            }

            return(dGroup);
        }
Beispiel #22
0
        protected override void OnRender(DrawingContext dc)
        {
            base.OnRender(dc);
            if (drawing == null)
            {
                drawing = GetDrawing();
                if (drawing == null)
                {
                    return;
                }
            }

            var cellSize = CellSize;
            var rotate   = new RotateTransform(-(int)Cell.Direction * 45, cellSize / 2, cellSize / 2);

            rotate.Freeze();
            dc.PushTransform(rotate);
            dc.DrawDrawing(drawing);
            dc.Pop();

            // 防止鼠标事件穿透
            dc.DrawRectangle(Brushes.Transparent, null, new Rect(new Size(cellSize, cellSize)));
        }
Beispiel #23
0
        protected override void InternalDraw(DrawingContext dc)
        {
            var renderSize = Element.RenderSize;

            dc.DrawRectangle(Brushes.Transparent, null, new Rect(renderSize));
            if (_sectionsCache == null || _maxRenderWidth < renderSize.Width)
            {
                _sectionWidth   = Element.Graduations.Count * Element.Interval;
                _maxRenderWidth = renderSize.Width;
                DrawSections();
            }

            //var max = Element.Graduations.Max();
            //得到相对于大容器的位置
            var viewPortWidth = Element.AxisPanel.ViewportRangeX.ViewMin;// Element.AxisXConverter.ScreenToViewport(0);//Element.AxisPanel.HorizontalOffset;
            //用段的模求出偏移量
            var xTranslateTransform = -viewPortWidth % (_sectionWidth);

            //Debug.Print(_sectionWidth.ToString());

            dc.PushClip(new RectangleGeometry(new Rect(renderSize)));
            dc.PushTransform(new TranslateTransform(xTranslateTransform, renderSize.Height - 14));//
            dc.DrawDrawing(_sectionsCache);
            dc.Pop();
            dc.Pop();

            MakeGuideLines(xTranslateTransform);

            var y = GetY();

            //draw base line
            if (Element.ShowBaseLine)
            {
                dc.DrawGuideLineLine(CreateSelectedLinePen(), new Point(0, y), new Point(renderSize.Width, y));
            }
        }
Beispiel #24
0
        //https://stackoverflow.com/questions/15779564/resize-image-in-wpf
        public static BitmapSource GetBitMapSource(ImageSource source, Double scale = 1.0, Double width = 0.0, Double height = 0.0, Double margin = 0.0)
        {
            width  = width == 0.0 ? source.Width * scale  : width;
            height = height == 0.0 ? source.Height * scale  : height;
            Rect         rect  = new Rect(margin, margin, width - margin * 2, height - margin * 2);
            DrawingGroup group = new DrawingGroup();

            RenderOptions.SetBitmapScalingMode(group, BitmapScalingMode.HighQuality);
            group.Children.Add(new ImageDrawing(source, rect));

            DrawingVisual drawingVisual = new DrawingVisual();

            using (DrawingContext drawingContext = drawingVisual.RenderOpen())
                drawingContext.DrawDrawing(group);

            RenderTargetBitmap bitmap = new RenderTargetBitmap(
                (int)width, (int)height, // Resized dimensions
                96, 96,                  // Default DPI values
                PixelFormats.Pbgra32);   // Default pixel format

            bitmap.Render(drawingVisual);

            return(BitmapFrame.Create(bitmap));
        }
Beispiel #25
0
        // Token: 0x0600350C RID: 13580 RVA: 0x000F0390 File Offset: 0x000EE590
        private void CloneVisualTree(ContainerVisual parent, Visual old)
        {
            DrawingVisual drawingVisual = new DrawingVisual();

            parent.Children.Add(drawingVisual);
            drawingVisual.Clip              = VisualTreeHelper.GetClip(old);
            drawingVisual.Offset            = VisualTreeHelper.GetOffset(old);
            drawingVisual.Transform         = VisualTreeHelper.GetTransform(old);
            drawingVisual.Opacity           = VisualTreeHelper.GetOpacity(old);
            drawingVisual.OpacityMask       = VisualTreeHelper.GetOpacityMask(old);
            drawingVisual.BitmapEffectInput = VisualTreeHelper.GetBitmapEffectInput(old);
            drawingVisual.BitmapEffect      = VisualTreeHelper.GetBitmapEffect(old);
            DrawingContext drawingContext = drawingVisual.RenderOpen();

            drawingContext.DrawDrawing(old.GetDrawing());
            drawingContext.Close();
            int childrenCount = VisualTreeHelper.GetChildrenCount(old);

            for (int i = 0; i < childrenCount; i++)
            {
                Visual old2 = old.InternalGetVisualChild(i);
                this.CloneVisualTree(drawingVisual, old2);
            }
        }
        protected void Arc(double x, double y, double w, double h, double start, double stop, ArcMode mode = ArcMode.Pie)
        {
            double startRadians = -start * Math.PI / 180.0;
            double sweepRadians = -(stop - start) * Math.PI / 180.0;

            double rx = w / 2;
            double ry = h / 2;

            double startX = x + rx + (Math.Cos(startRadians) * rx);
            double startY = y + ry + (Math.Sin(startRadians) * ry);

            double endX = x + rx + (Math.Cos(startRadians + sweepRadians) * rx);
            double endY = y + ry + (Math.Sin(startRadians + sweepRadians) * ry);

            var geometry = new StreamGeometry();

            using (var ctx = geometry.Open())
            {
                bool isLargeArc = Math.Abs(stop - start) > 180;
                var  direction  = sweepRadians < 0 ? SweepDirection.Counterclockwise : SweepDirection.Clockwise;
                ctx.BeginFigure(new System.Windows.Point(startX, startY), mode != ArcMode.Open, mode != ArcMode.Open);
                ctx.ArcTo(new System.Windows.Point(endX, endY), new System.Windows.Size(rx, ry), 0, isLargeArc, direction, ShouldStroke(), false);
                if (mode == ArcMode.Pie)
                {
                    ctx.LineTo(new System.Windows.Point(x + rx, y + ry), ShouldStroke(), false);
                    ctx.LineTo(new System.Windows.Point(startX, startY), ShouldStroke(), false);
                }
            }

            var drawing = new GeometryDrawing();

            drawing.Geometry = geometry;
            drawing.Pen      = ShouldStroke() ? pen : null;
            drawing.Brush    = ShouldFill() ? fillBrush : null;
            context.DrawDrawing(drawing);
        }
Beispiel #27
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            Debug.WriteLine($"RRRRRRRRRRRR {Count:D5} {Environment.TickCount} {Environment.TickCount - MainWindow.TouchTickCount:D5} {Environment.TickCount - TickCount:D5}");

            TickCount = Environment.TickCount;

            var bounds         = DrawingVisual.DescendantBounds;
            var width          = Width;
            var height         = Height;
            var scaleTransform = ScaleTransform;

            if (double.IsNaN(width) || double.IsNaN(height))
            {
                scaleTransform.ScaleX = 1;
                scaleTransform.ScaleY = 1;
            }
            else
            {
                scaleTransform.ScaleX = width / bounds.Width;
                scaleTransform.ScaleY = height / bounds.Height;
            }

            TranslateTransform.X = X;
            TranslateTransform.Y = Y;

            RotateTransform.Angle = Rotation;
            var rect        = new Rect(X, Y, Width, Height);
            var centerPoint = Center(rect);

            RotateTransform.CenterX = centerPoint.X;
            RotateTransform.CenterY = centerPoint.Y;

            drawingContext.PushTransform(TransformGroup);
            drawingContext.DrawDrawing(DrawingVisual.Drawing);
            drawingContext.Pop();
        }
        BitmapSource CreateSymbolBitmap(SymbolID symbolID, Color color, bool dark)
        {
            DrawingVisual  drawingVisual  = new DrawingVisual();
            DrawingContext drawingContext = drawingVisual.RenderOpen();

            Drawing d = m_symbolDrawingCache.GetDrawing(symbolID, color);

            drawingContext.PushTransform(new ScaleTransform(Math.Floor(m_size) / 100, Math.Floor(m_size) / 100));
            drawingContext.DrawDrawing(d);
            drawingContext.Pop();

            drawingContext.Close();

            if (dark)
            {
                drawingVisual.Opacity = 0.2;
            }

            RenderTargetBitmap bmp = new RenderTargetBitmap((int)m_size, (int)m_size, 96, 96, PixelFormats.Default);

            bmp.Render(drawingVisual);
            bmp.Freeze();
            return(bmp);
        }
Beispiel #29
0
 protected override void OnRender(DrawingContext drawingContext)
 {
     base.OnRender(drawingContext);
     drawingContext.DrawDrawing(Group);
 }
Beispiel #30
0
        private void Draw(DrawingGroup group, DrawingGroup main)
        {
            DrawingVisual drawingVisual = new DrawingVisual();

            DrawingContext drawingContext = drawingVisual.RenderOpen();

            _offsetX          = 0;
            _offsetY          = 0;
            _displayTransform = Transform.Identity;

            TranslateTransform offsetTransform = null;
            Rect rectBounds = group.Bounds;

            if (!rectBounds.IsEmpty)
            {
                // Return the new size
                //double diaWidth = rectBounds.Width;
                if (rectBounds.X > 0)
                {
                    //diaWidth += rectBounds.X;
                    _offsetX = rectBounds.X;
                }
                //double diaHeight = rectBounds.Height;
                if (rectBounds.Y > 0)
                {
                    //diaHeight += rectBounds.Y;
                    _offsetY = rectBounds.Y;
                }

                _bounds = rectBounds;

                if (_offsetX > 0 || _offsetY > 0)
                {
                    offsetTransform   = new TranslateTransform(-_offsetX, -_offsetY);
                    _displayTransform = new TranslateTransform(_offsetX, _offsetY); // the inverse...
                }
            }

            //Canvas.SetTop(this, -_offsetX);
            //Canvas.SetLeft(this, -_offsetY);

            //if (offsetTransform != null)
            //{
            //    drawingContext.PushTransform(offsetTransform);
            //}

            drawingContext.DrawDrawing(group);

            //if (offsetTransform != null)
            //{
            //    drawingContext.Pop();
            //}

            drawingVisual.Opacity = group.Opacity;

            //Transform transform = group.Transform;
            //if (transform == null)
            //{
            //    transform = offsetTransform;
            //}
            if (offsetTransform != null)
            {
                drawingVisual.Transform = offsetTransform;
            }
            Geometry clipGeometry = group.ClipGeometry;

            if (clipGeometry != null)
            {
                drawingVisual.Clip = clipGeometry;
            }

            drawingContext.Close();

            this.AddVisual(drawingVisual);

            if (_drawForInteractivity)
            {
                if (main == null)
                {
                    main = group;
                }

                this.EnumerateDrawings(main);
            }
        }