public virtual IDisposable Draw(DrawingContext drawingContext, Rect targetItemRect, int level)
        {
            //Default is to draw the image bits into the context:

            //Do not dispose of the memory stream here, because System.Media.Windows uses
            // retained mode rendering where the commands get batched to execute later.
            MemoryStream imageStream = new MemoryStream(this.ImageData);
            try
            {
                TransformedBitmap shrunkImage = ResizePng(imageStream, targetItemRect.Size);

                //DrawingContext.DrawImage will scale an image to fill the size, so modify
                // our target rect to be exactly the correct image position on the tile.
                Rect targetImageRect = new Rect(targetItemRect.X, targetItemRect.Y,
                    shrunkImage.PixelWidth, shrunkImage.PixelHeight);
                drawingContext.DrawImage(shrunkImage, targetImageRect);

                return imageStream; //Return our stream so it can be disposed later.
            }
            catch
            {
                if (null != imageStream)
                {
                    imageStream.Dispose();
                }
                throw;
            }
        }
 protected override void DrawTile(DrawingContext dc, Rect TileRect)
 {
     if (!_tileImage.IsReady)
         dc.DrawRectangle(Brushes.LemonChiffon, null, TileRect);
     else
         dc.DrawImage(_tileImage.Image, TileRect);
 }
Exemple #3
1
        private void Render(DrawingContext drawingContext)
        {
            if (_width > 0 && _height > 0)
            {
                if (_bitmap == null || _bitmap.Width != _width || _bitmap.Height != _height)
                {
                    _bitmap = new WriteableBitmap(_width, _height, 96, 96, PixelFormats.Pbgra32, null);
                }

                _bitmap.Lock();
                using (var surface = SKSurface.Create(_width, _height, SKImageInfo.PlatformColorType, SKAlphaType.Premul, _bitmap.BackBuffer, _bitmap.BackBufferStride))
                {
                    var canvas = surface.Canvas;
                    canvas.Scale((float)_dpiX, (float)_dpiY);
                    canvas.Clear();
                    using (new SKAutoCanvasRestore(canvas, true))
                    {
                        Presenter.Render(canvas, Renderer, Container, _offsetX, _offsetY);
                    }
                }
                _bitmap.AddDirtyRect(new Int32Rect(0, 0, _width, _height));
                _bitmap.Unlock();

                drawingContext.DrawImage(_bitmap, new Rect(0, 0, _actualWidth, _actualHeight));
            }
        }
        protected override void OnRender(DrawingContext drawingContext)
        {
            PushButton pushButton = Visual as PushButton;
            if (pushButton.Pushed && _pushedImage != null)
            {
                drawingContext.DrawImage(_pushedImage, _imageRect);
            }
            else if (_image != null)
            {
                drawingContext.DrawImage(_image, _imageRect);
            }

            if (pushButton.Pushed)
            {
                drawingContext.PushTransform(new TranslateTransform(pushButton.TextPushOffset.X, pushButton.TextPushOffset.Y));
            }

            if (pushButton.Glyph != PushButtonGlyph.None)
            {
                drawingContext.DrawGeometry(_glyphBrush, _glyphPen, _glyphPath);
            }
            pushButton.TextFormat.RenderText(drawingContext, _textBrush, pushButton.Text, _imageRect);

            if (pushButton.Pushed)
            {
                drawingContext.Pop();
            }
        }
 protected override void OnRender(DrawingContext drawingContext)
 {
     ToggleSwitch toggleSwitch = Visual as ToggleSwitch;
     if (toggleSwitch != null)
     {
         switch (toggleSwitch.SwitchPosition)
         {
             case ToggleSwitchPosition.One:
                 if (toggleSwitch.HasIndicator && toggleSwitch.IndicatorOn && _imageOneIndicatorOn != null)
                 {
                     drawingContext.DrawImage(_imageOneIndicatorOn, _imageRect);
                 }
                 else
                 {
                     drawingContext.DrawImage(_imageOne, _imageRect);
                 }
                 break;
             case ToggleSwitchPosition.Two:
                 if (toggleSwitch.HasIndicator && toggleSwitch.IndicatorOn && _imageOneIndicatorOn != null)
                 {
                     drawingContext.DrawImage(_imageTwoIndicatorOn, _imageRect);
                 }
                 else
                 {
                     drawingContext.DrawImage(_imageTwo, _imageRect);
                 }
                 break;
         }
     }
 }
 protected override void OnRender(DrawingContext drawingContext)
 {
     GuardedToggleSwitch toggleSwitch = Visual as GuardedToggleSwitch;
     if (toggleSwitch != null)
     {
         switch (toggleSwitch.SwitchPosition)
         {
             case ToggleSwitchPosition.One:
                 if (toggleSwitch.GuardPosition == GuardPosition.Up)
                 {
                     drawingContext.DrawImage(_imageOneGuardUp, _imageRect);
                 }
                 else
                 {
                     drawingContext.DrawImage(_imageOneGuardDown, _imageRect);
                 }
                 break;
             case ToggleSwitchPosition.Two:
                 if (toggleSwitch.GuardPosition == GuardPosition.Up)
                 {
                     drawingContext.DrawImage(_imageTwoGuardUp, _imageRect);
                 }
                 else
                 {
                     drawingContext.DrawImage(_imageTwoGuardDown, _imageRect);
                 }
                 break;
         }
     }
 }
Exemple #7
0
		public void drawLimb(DrawingContext dc, Point p1, Point p2, int margin)
		{

			dc.PushTransform(new TranslateTransform(p1.X, p1.Y));
			
			Vector diff = p2 - p1;
			diff.Normalize();

			double angle = Math.Acos(diff.Y) * (180.0 / Math.PI);
			if (Double.IsNaN(angle))
				angle = 0;

            if (Double.IsNaN(diff.X))
                diff.X = 0;

			dc.PushTransform(new RotateTransform(Math.Sign(diff.X) * (-1) * angle));

			Vector diff2 = p2 - p1;
			double scale = diff2.Length / (this.Height - 2 * margin);
			dc.PushTransform(new ScaleTransform(1, scale));

			dc.PushTransform(new TranslateTransform(-this.Width / 2.0, -margin));

			
			dc.DrawImage(this.Image, new Rect(0, 0, this.Width, this.Height));

			dc.Pop();
			dc.Pop();
			dc.Pop();
			dc.Pop();
		}
        protected override void OnRender(System.Windows.Media.DrawingContext dc)
        {
            base.OnRender(dc);

            if (Screen.Name == Screen.Stage.StartScreen)
            {
                var p = Screen.Stage.StartPoint;
                dc.DrawImage(StartIcon, new System.Windows.Rect(Zoom * (p.X - StartIcon.PixelWidth / 2), Zoom * (p.Y - StartIcon.PixelHeight / 2), Zoom * StartIcon.PixelWidth, Zoom * StartIcon.PixelHeight));
            }

            if (Screen.Stage.ContinuePoints.ContainsKey(Screen.Name))
            {
                var p = Screen.Stage.ContinuePoints[Screen.Name];
                dc.DrawImage(ContinueIcon, new System.Windows.Rect(Zoom * (p.X - ContinueIcon.PixelWidth / 2), Zoom * (p.Y - ContinueIcon.PixelHeight / 2), Zoom * ContinueIcon.PixelWidth, Zoom * ContinueIcon.PixelHeight));
            }
        }
        public void Draw(ApplicationContext actx, SWM.DrawingContext dc, double scaleFactor, double x, double y, ImageDescription idesc)
        {
            if (drawCallback != null)
            {
                DrawingContext c = new DrawingContext(dc, scaleFactor);
                actx.InvokeUserCode(delegate {
                    drawCallback(c, new Rectangle(x, y, idesc.Size.Width, idesc.Size.Height));
                });
            }
            else
            {
                if (idesc.Alpha < 1)
                {
                    dc.PushOpacity(idesc.Alpha);
                }

                var f        = GetBestFrame(actx, scaleFactor, idesc.Size.Width, idesc.Size.Height, false);
                var bmpImage = f as BitmapSource;
                if (bmpImage != null && (bmpImage.PixelHeight != idesc.Size.Height || bmpImage.PixelWidth != idesc.Size.Width))
                {
                    f = new TransformedBitmap(bmpImage, new ScaleTransform(idesc.Size.Width / bmpImage.PixelWidth, idesc.Size.Height / bmpImage.PixelHeight));
                }
                dc.DrawImage(f, new Rect(x, y, idesc.Size.Width, idesc.Size.Height));

                if (idesc.Alpha < 1)
                {
                    dc.Pop();
                }
            }
        }
        protected override void OnRender(DrawingContext drawingContext)
        {
            if (Uniter == null) return;

            List<Rect> rects = Uniter.Members
                                     .Select(m => new Rect(m.PointToScreen(new Point(0, 0)), m.RenderSize))
                                     .ToList();

            Point p1 = PointFromScreen(new Point(rects.Min(r => r.X),
                                                 rects.Min(r => r.Y)));
            Point p2 = PointFromScreen(new Point(rects.Max(r => r.X + r.Width),
                                                 rects.Max(r => r.Y + r.Height)));

            var renderRect = new Rect(p1, p2);

            base.OnRender(drawingContext);

            double verticalPixelScrollRange = renderRect.Height * Math.Abs(Uniter.VerticalScrollRange);
            double canvasHeight = renderRect.Height + verticalPixelScrollRange;
            double canvasWidth = renderRect.Width;

            double scale = Math.Max(canvasWidth / Source.Width, canvasHeight / Source.Height);

            double imageWidth = Source.Width * scale;
            double imageHeight = Source.Height * scale;

            double y = Uniter.VerticalOffset * verticalPixelScrollRange;

            drawingContext.DrawImage(Source, new Rect(renderRect.X, renderRect.Y - y, imageWidth, imageHeight));
        }
 private void DrawImageOperations(DrawingContext drawingContext, IEnumerable<DrawingOperation> opeations)
 {
     foreach (var oper in opeations)
     {
         drawingContext.DrawImage(oper.Image, oper.DestRect);
     }
 }
        protected override void OnRender(DrawingContext dc)
        {
            var bitmap = new WriteableBitmap((int)(Screen.PixelWidth * this.Zoom), (int)(Screen.PixelHeight * this.Zoom), 96, 96, PixelFormats.Pbgra32, null);

            base.OnRender(dc);

            var size = Screen.Tileset.TileSize * this.Zoom;

            for (int y = 0; y < Screen.Height; y++)
            {
                for (int x = 0; x < Screen.Width; x++)
                {
                    var tile = Screen.TileAt(x, y);
                    var location = tile.Sprite.CurrentFrame.SheetLocation;
                    var rect = new Rect(0, 0, location.Width, location.Height);

                    if (_grayscale)
                    {
                        var image = SpriteBitmapCache.GetOrLoadFrameGrayscale(Screen.Tileset.SheetPath.Absolute, location);
                        bitmap.Blit(new Rect(x * size, y * size, size, size), image, rect);
                    }
                    else
                    {
                        var image = SpriteBitmapCache.GetOrLoadFrame(Screen.Tileset.SheetPath.Absolute, location);
                        bitmap.Blit(new Rect(x * size, y * size, size, size), image, rect);
                    }
                }
            }

            dc.DrawImage(bitmap, new Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight));
        }
Exemple #13
0
        public void Draw(ApplicationContext actx, SWM.DrawingContext dc, double scaleFactor, double x, double y, ImageDescription idesc)
        {
            if (drawCallback != null)
            {
                DrawingContext c = new DrawingContext(dc, scaleFactor);
                actx.InvokeUserCode(delegate {
                    drawCallback(c, new Rectangle(x, y, idesc.Size.Width, idesc.Size.Height));
                });
            }
            else
            {
                if (idesc.Alpha < 1)
                {
                    dc.PushOpacity(idesc.Alpha);
                }

                var f = GetBestFrame(actx, scaleFactor, idesc.Size.Width, idesc.Size.Height, false);
                dc.DrawImage(f, new Rect(x, y, idesc.Size.Width, idesc.Size.Height));

                if (idesc.Alpha < 1)
                {
                    dc.Pop();
                }
            }
        }
Exemple #14
0
        public void Draw(LayerModel layer, DrawingContext c)
        {
            var props = (KeyboardPropertiesModel) layer.Properties;
            if (string.IsNullOrEmpty(props.GifFile))
                return;
            if (!File.Exists(props.GifFile))
                return;

            // Only reconstruct GifImage if the underlying source has changed
            if (layer.GifImage == null)
                layer.GifImage = new GifImage(props.GifFile);
            if (layer.GifImage.Source != props.GifFile)
                layer.GifImage = new GifImage(props.GifFile);

            var rect = new Rect(layer.AppliedProperties.X*4,
                layer.AppliedProperties.Y*4,
                layer.AppliedProperties.Width*4,
                layer.AppliedProperties.Height*4);

            lock (layer.GifImage)
            {
                var draw = layer.GifImage.GetNextFrame();
                c.DrawImage(ImageUtilities.BitmapToBitmapImage(new Bitmap(draw)), rect);
            }
        }
Exemple #15
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            if (sample == null)
                return;

            var m = PresentationSource.FromVisual(this).CompositionTarget.TransformToDevice;
            var dpiX = m.M11;
            var dpiY = m.M22;

            int width = (int)(ActualWidth * dpiX);
            int height = (int)(ActualHeight * dpiY);

            var bitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Pbgra32, null);
            bitmap.Lock();
            using (var surface = SKSurface.Create(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul, bitmap.BackBuffer, bitmap.BackBufferStride))
            {
                var skcanvas = surface.Canvas;
                skcanvas.Scale((float)dpiX, (float)dpiY);
                using (new SKAutoCanvasRestore(skcanvas, true))
                {
                    sample.Method(skcanvas, (int)ActualWidth, (int)ActualHeight);
                }
            }
            bitmap.AddDirtyRect(new Int32Rect(0, 0, width, height));
            bitmap.Unlock();

            drawingContext.DrawImage(bitmap, new Rect(0, 0, ActualWidth, ActualHeight));
        }
Exemple #16
0
        protected override void OnRender(System.Windows.Media.DrawingContext dc)
        {
            base.OnRender(dc);

            foreach (var placement in Screen.Entities)
            {
                var entity = Screen.Stage.Project.EntityByName(placement.entity);

                if (entity != null)
                {
                    var sprite = entity.DefaultSprite;
                    if (sprite != null)
                    {
                        var frame = SpriteBitmapCache.GetOrLoadFrame(sprite.SheetPath.Absolute, sprite.CurrentFrame.SheetLocation);

                        var flip = (placement.direction == Common.Direction.Left) ^ sprite.Reversed;
                        int hx   = flip ? sprite.Width - sprite.HotSpot.X : sprite.HotSpot.X;

                        dc.DrawImage(frame, new Rect(this.Zoom * (placement.screenX - hx), this.Zoom * (placement.screenY - sprite.HotSpot.Y), this.Zoom * frame.PixelWidth, this.Zoom * frame.PixelHeight));

                        continue;
                    }
                }

                dc.DrawEllipse(Brushes.Orange, null, new System.Windows.Point(this.Zoom * placement.screenX, this.Zoom * placement.screenY), 10 * Zoom, 10 * Zoom);
            }
        }
 public void draw(DrawingContext dc)
 {
     leftBall.draw(dc);
     rightBall.draw(dc);
     dc.DrawImage(scoreBoard, new Rect(new Point(width / 2 - 250, 0), new Point(width / 2, 150)));
     leftHoop.draw(dc);
     rightHoop.draw(dc);
 }
 protected override void OnRender(DrawingContext dc)
 {
     base.OnRender(dc);
     if (ScreenShot.IsNotNull())
     {
         dc.DrawImage(ScreenShot,new Rect(new System.Windows.Point(0,0), new System.Windows.Size((int)this.Width,(int)this.Height)));
     }
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dc"></param>
        protected override void OnRender(DrawingContext dc)
        {
            if (RnaRunner == null)
                return;

            var bitmapSource = BitmapConverter.Convert(RnaRunner.PixelMap);

            dc.DrawImage(bitmapSource, new Rect(0, 0, 600, 600));
        }
Exemple #20
0
 protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
 {
     if (_bitmap != null)
     {
         drawingContext.PushClip(new RectangleGeometry(new Rect(RenderSize)));
         drawingContext.DrawImage(_bitmap, new Rect(new Size(_bitmap.Width, _bitmap.Height)));
         drawingContext.Pop();
     }
 }
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            _scopeBrush = new SolidColorBrush(Color.FromRgb(255, 0, 0));
            Pen _scopePen = new Pen(_scopeBrush, 1d);


            CustomNeedle customNeedle = Visual as CustomNeedle;

            if (customNeedle != null)
            {
                drawingContext.DrawImage(_bgplate_image, _bgplate_imageRect);

                drawingContext.PushTransform(new RotateTransform(customNeedle.KnobRotation, _center.X, _center.Y));
                drawingContext.DrawImage(_image, _imageRect);
                drawingContext.DrawLine(_scopePen, _center, _punto); //draw rotation point for reference
                drawingContext.Pop();
            }
        }
Exemple #22
0
        protected override void OnRender(DrawingContext dc)
        {
            base.OnRender(dc);

            if (_bitmap == null)
                return;

            Tracing.Log(">> CreateBitmap - OnRender - Drawing bitmap");
            dc.DrawImage(_bitmap, new Rect(0, 0, 100, 100));
        }   
Exemple #23
0
 internal static void DrawPicture(ImageSource imageSource, Rect rect, DrawingContext context)
 {
     if (imageSource != null)
     {
         double imageWidth = imageSource.Width;
         double imageHeight = imageSource.Height;
         context.DrawImage(imageSource, new Rect(rect.X + (rect.Width - imageWidth) / 2,
             rect.Y + (rect.Height - imageHeight) / 2, imageWidth, imageHeight));
     }
 }
Exemple #24
0
        protected override void ApplyFilter(FastBitmap source, DrawingContext dc, int width, int height)
        {
            // Draw border.
            dc.DrawRectangle(Fill.GetBrush(), null, new Rect(0, 0, width, height));

            // Draw image.
            dc.PushTransform(new TranslateTransform(Width, Width));
            dc.DrawImage(source.InnerBitmap, new Rect(0, 0, source.Width, source.Height));
            dc.Pop();
        }
        protected override void OnRender(DrawingContext dc)
        {
            base.OnRender(dc);

            var image = SpriteBitmapCache.GetOrLoadFrame(_playerSprite.SheetPath.Absolute, _playerSprite.CurrentFrame.SheetLocation);
            image = SpriteBitmapCache.Scale(image, this.Zoom);

            if (Screen.Name == Screen.Stage.StartScreen)
            {
                var p = Screen.Stage.StartPoint;
                dc.DrawImage(image, new System.Windows.Rect(Zoom * (p.X - _playerSprite.HotSpot.X), Zoom * (p.Y - _playerSprite.HotSpot.Y), image.PixelWidth, image.PixelHeight));
            }

            if (Screen.Stage.ContinuePoints.ContainsKey(Screen.Name))
            {
                var p = Screen.Stage.ContinuePoints[Screen.Name];
                dc.DrawImage(image, new System.Windows.Rect(Zoom * (p.X - _playerSprite.HotSpot.X), Zoom * (p.Y - _playerSprite.HotSpot.Y), image.PixelWidth, image.PixelHeight));
            }
        }
Exemple #26
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            ImageSource image = _indicator.On ? _onImage : _offImage;
            if (image == null)
            {
                image = _indicator.On ? _offImage : _onImage;
            }

            drawingContext.DrawImage(image, _imageRect);
            _indicator.TextFormat.RenderText(drawingContext, _indicator.On ? _onBrush : _offBrush, _indicator.Text, _imageRect);
        }
Exemple #27
0
        protected override void OnRender(DrawingContext dc)
        {
            BitmapSource bitmapSource = Source;
            if (bitmapSource != null)
            {
                _pixelOffset = GetPixelOffset();

                // Render the bitmap offset by the needed amount to align to pixels.
                dc.DrawImage(bitmapSource, new Rect(_pixelOffset, DesiredSize));
            }
        }
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            Rotary rotary = Visual as Rotary;

            if (rotary != null)
            {
                drawingContext.PushTransform(new RotateTransform(rotary.KnobRotation, _center.X, _center.Y));
                drawingContext.DrawImage(_image, _imageRect);
                drawingContext.Pop();
            }
        }
 protected override void OnRender(DrawingContext drawingContext)
 {
     if (VectorIcon != null)
         return;
     var size = new Size(Math.Max(0.0, RenderSize.Width - Padding.Left - Padding.Right),
         Math.Max(0.0, RenderSize.Height - Padding.Top - Padding.Bottom));
     CoerceOptimalImageForSize(size);
     if (_optimalImageForSize == null)
         return;
     drawingContext.DrawImage(_optimalImageForSize, new Rect(new Point(Padding.Left, Padding.Top), size));
 }
Exemple #30
0
        public void Draw(DrawingContext g)
        {
            // 1. Draw BG
            g.DrawImage(BG, new Rect(0, 0, Width, Height));

            // 2. Create text objects
            var scoreTitle = GetText("Score:");
            var scoreText = GetText(Game.Score.ToString());

            var livesTitle = GetText("Balls: ");
            livesTitle.SetTextDecorations(new TextDecorationCollection(TextDecorations.Underline));
            scoreTitle.SetTextDecorations(new TextDecorationCollection(TextDecorations.Underline));

            var livesText = GetText(Game.Lives.ToString());

            // 3. Draw the stuff
            g.PushTransform(new TranslateTransform(Width / 4f, Height / 3.5f));
            {
                g.DrawText(scoreTitle, new Point(0, 0));
                g.DrawText(scoreText, new Point(scoreTitle.Width + 10, 0));
                g.DrawText(livesTitle, new Point(0, scoreTitle.Height + 5));

                // --- Lives ---
                int i = 0;
                for (; i < Game.Lives; i++)
                {
                    g.DrawImage(Line, new Rect(livesTitle.Width + (i + 1) * lineWidth, scoreText.Height + 5, lineWidth, lineHeight));
                }
                for (; i < Game.TOTAL_LIVES; i++)
                {
                    g.DrawImage(LineThrough, new Rect(livesTitle.Width + (i + 1) * lineWidth, scoreText.Height + 5, lineWidth, lineHeight));
                }

                g.PushTransform(new TranslateTransform(Width / 6, livesTitle.Height * 2));
                {
                    // --- Smilie ---
                    if (Game.Lives < Game.TOTAL_LIVES / 3)
                    {
                        g.DrawImage(BadSmilie, new Rect(0, 0, smilieWidth, smilieHeight));
                    }
                    else if (Game.Lives < Game.TOTAL_LIVES / 3 * 2)
                    {
                        g.DrawImage(MediumSmilie, new Rect(0, 0, smilieWidth, smilieHeight));
                    }
                    else
                    {
                        g.DrawImage(GoodSmilie, new Rect(0, 0, smilieWidth, smilieHeight));
                    }
                }
                g.Pop();
            }
            g.Pop();
        }
Exemple #31
0
        /// <summary>
        /// Renders the specified map viewer.
        /// </summary>
        /// <param name="mapViewer">The map viewer.</param>
        /// <param name="drawingContext">The drawing context.</param>
        /// <param name="playerColor">Color of the player.</param>
        public void Render(CustomControls.MapViewer mapViewer, System.Windows.Media.DrawingContext drawingContext, System.Windows.Media.Color playerColor)
        {
            if (mapViewer.IsInView(casePosition))
            {
                Rect rect = mapViewer.GetRectangle((int)casePosition.X, (int)casePosition.Y);

                drawingContext.DrawImage(Tile, rect);
                SolidColorBrush myBrush = new SolidColorBrush(playerColor);
                myBrush.Opacity = 0.3;
                drawingContext.DrawRectangle(myBrush, null, rect);
            }
        }
Exemple #32
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            TransformGroup transform = new TransformGroup();

            transform.Children.Add(new TranslateTransform((-_center.X + HorizontalOffset) * _xScale, (-_center.Y + VerticalOffset) * _yScale));
            transform.Children.Add(new RotateTransform(_rotation + _baseRotation));
            transform.Children.Add(new TranslateTransform(_location.X * _xScale, _location.Y * _yScale));

            drawingContext.PushTransform(transform);
            drawingContext.DrawImage(_image, _rectangle);
            drawingContext.Pop();
        }
        protected override void ApplyFilter(FastBitmap source, DrawingContext dc, int width, int height)
        {
            // Draw image.
            dc.PushTransform(new TranslateTransform(BorderWidth, BorderWidth));
            dc.DrawImage(source.InnerBitmap, new Rect(0, 0, source.Width, source.Height));
            dc.Pop();

            // Draw border.
            dc.DrawRoundedRectangle(null, new Pen(new SolidColorBrush(BorderColor), BorderWidth),
                new Rect(BorderWidth / 2.0, BorderWidth / 2.0, width - BorderWidth, height - BorderWidth),
                Roundness, Roundness);
        }
Exemple #34
0
        public void DrawCircle(Point center, DrawingContext drawingContext, Size windowSize, bool drawCircle)
        {
            var rectangle = new Rect(center.X - Radius, center.Y - Radius, Radius * 2, Radius * 2);
            var path = new PathGeometry();
            path.AddGeometry(new EllipseGeometry(rectangle));
            drawingContext.PushClip(path);
            var windowRect = new Rect(windowSize);
            drawingContext.DrawImage(Bitmap, windowRect);

            if (drawCircle)
                drawingContext.DrawEllipse(Brushes.Transparent, new Pen(Brushes.Red, 1.5), center, Radius, Radius);
        }
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            Metric metric = Visual as Metric;

            if (metric != null)
            {
                drawingContext.PushTransform(new TranslateTransform(metric.MetricTranslationX, metric.MetricTranslationY));
                drawingContext.PushTransform(new RotateTransform(metric.MetricRotation, _center.X, _center.Y - metric.MetricTranslationY));
                drawingContext.DrawImage(_image, _imageRect);
                drawingContext.Pop( );
            }
        }
Exemple #36
0
        protected override void OnRender(DrawingContext dc)
        {
            if (_frames.Count == 0)
            {
                base.OnRender(dc);
                return;
            }

            var minSize = Math.Max(RenderSize.Width, RenderSize.Height);
            var frame = _frames.FirstOrDefault(f => f.Width >= minSize && f.Height >= minSize) ?? _frames.Last();
            dc.DrawImage(frame, new Rect(0, 0, RenderSize.Width, RenderSize.Height));
        }
Exemple #37
0
 /// <summary>
 /// Applies the <see cref="RotationFilter" /> to the specified <paramref name="source"/>.
 /// </summary>
 protected override void ApplyFilter(FastBitmap source, DrawingContext dc, int width, int height)
 {
     dc.PushTransform(new TransformGroup
     {
         Children = new TransformCollection
         {
             _rotateTransform,
             new TranslateTransform((width - source.Width) / 2.0, (height - source.Height) / 2.0)
         }
     });
     dc.DrawImage(source.InnerBitmap, new Rect(0, 0, source.Width, source.Height));
     dc.Pop();
 }
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            if (_bitmap != null)
            {
                var bitmapSize         = new Vector(_bitmap.Width, _bitmap.Height);
                var dpiScaleToWpfScale = CurrentHwndSource.CompositionTarget.TransformFromDevice;
                var adjustedBitmapSize = dpiScaleToWpfScale.Transform(bitmapSize);

                drawingContext.PushClip(new RectangleGeometry(new Rect(RenderSize)));
                drawingContext.DrawImage(_bitmap, new Rect(new Size(adjustedBitmapSize.X, adjustedBitmapSize.Y)));
                drawingContext.Pop();
            }
        }
Exemple #39
0
        protected override void OnRender(System.Windows.Media.DrawingContext dc)
        {
            if (DrawImageWith9Cells == false)
            {
                base.OnRender(dc);
                return;
            }

            BitmapSource image       = (BitmapSource)this.Source;
            BitmapSource resultImage = this.Create9CellImage(image, new Int32Rect(5, 31, image.PixelWidth - 10, image.PixelHeight - 31 - 34), (int)this.Width, (int)this.Height);

            dc.DrawImage(resultImage, new Rect(0, 0, this.Width, this.Height));
        }
Exemple #40
0
        private void DrawGlyph(int x, int y, Cell c, Media.DrawingContext dc)
        {
            List <Media.Color> palette = new List <Media.Color>();

            palette.Add(GetColor(c.Back));
            palette.Add(GetColor(c.Fore));
            BitmapPalette p = new BitmapPalette(palette);

            BitmapSource bitmap = BitmapSource.Create(CellWidth, CellHeight,
                                                      96, 96, pixelFormat, p,
                                                      glyphTypeface[c.Char ?? ' '], rawStride);

            dc.DrawImage(bitmap, new Rect(x * CellWidth, y * CellHeight, CellWidth, CellHeight));
        }
        /// <summary>
        /// Renders the preview image.
        /// </summary>
        /// <param name="drawingContext"></param>
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            if (PreviewBitmap == null)
            {
                return;
            }

            Rect placement = calculateRectSize();

            System.Windows.Media.Pen renderPen = new System.Windows.Media.Pen(new SolidColorBrush(Colors.DarkGray), 1.5);

            drawingContext.DrawRectangle(null, renderPen, placement);
            drawingContext.DrawImage(previewBitmap, placement);
        }
        protected override void OnRender(DrawingContext dc)
        {
            if (_frames.Count == 0)
            {
                base.OnRender(dc);
                return;
            }

            switch (MultiFrameImageMode) {
                case MultiFrameImageMode.ScaleDownLargerFrame:
                    var minSize = Math.Max(RenderSize.Width, RenderSize.Height);
                    var minFrame = _frames.FirstOrDefault(f => f.Width >= minSize && f.Height >= minSize) ?? _frames.Last();
                    dc.DrawImage(minFrame, new Rect(0, 0, RenderSize.Width, RenderSize.Height));
                    break;
                case MultiFrameImageMode.NoScaleSmallerFrame:
                    var maxSize = Math.Min(RenderSize.Width, RenderSize.Height);
                    var maxFrame = _frames.LastOrDefault(f => f.Width <= maxSize && f.Height >= maxSize) ?? _frames.First();
                    dc.DrawImage(maxFrame, new Rect((RenderSize.Width-maxFrame.Width)/2, (RenderSize.Height - maxFrame.Height) / 2, maxFrame.Width, maxFrame.Height));
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
Exemple #43
0
 protected override void OnRender(DrawingContext drawingContext)
 {
     if (_switch != null)
     {
         switch (_switch.SwitchPosition)
         {
             case HatSwitchPosition.Center:
                 drawingContext.DrawImage(_centerImage, _imageRect);
                 break;
             case HatSwitchPosition.Up:
                 drawingContext.DrawImage(_upImage, _imageRect);
                 break;
             case HatSwitchPosition.Down:
                 drawingContext.DrawImage(_downImage, _imageRect);
                 break;
             case HatSwitchPosition.Left:
                 drawingContext.DrawImage(_leftImage, _imageRect);
                 break;
             case HatSwitchPosition.Right:
                 drawingContext.DrawImage(_rightImage, _imageRect);
                 break;
         }
     }
 }
Exemple #44
0
        protected void RenderTiles(System.Windows.Media.DrawingContext dc)
        {
            double opacityIncrement = 1.0f / Layers.Count;
            double opacity          = opacityIncrement;

            foreach (Layer layer in Layers)
            {
                dc.PushOpacity(opacity);
                foreach (Sprite sprite in layer.Tiles)
                {
                    dc.DrawImage(sprite.ImageSource, sprite.Rect);
                }
                dc.Pop();
                opacity += opacityIncrement;
            }
        }
        /// <summary>
        /// The overridden OnRender method that displays image on top of attached UIElement.
        /// </summary>
        /// <param name="drawingContext">The drawing context object.</param>
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            if (this.sortGlyph != null)
            {
                double x = this.columnHeader.ActualWidth - 13;
                double y = (this.columnHeader.ActualHeight / 2) - 5;
                Rect rect = new Rect(x, y, 10, 10);
                drawingContext.DrawImage(this.sortGlyph, rect);
            }
            else
            {
                drawingContext.DrawGeometry(Brushes.LightGray, new Pen(Brushes.Gray, 1.0), this.GetDefaultGlyph());
            }
        }
Exemple #46
0
        //public bool SoftwareRendering {
        //    get { return ((System.Windows.Interop.RenderMode)GetValue(RenderOptions.ProcessRenderMode)) == System.Windows.Interop.RenderMode.SoftwareOnly; }
        //    set { SetValue(RenderOptions.ProcessRenderMode, value ? System.Windows.Interop.RenderMode.SoftwareOnly : System.Windows.Interop.RenderMode.Default); }
        //}

        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);
            SineRenderMode renderMode = SineRenderMode;

            drawingContext.DrawText(
                new FormattedText(
                    "ViewportHOffset: " + ViewportHorizontalOffset + " ViewportWidth: " + ViewportWidth + ", RenderMode: " + renderMode,
                    CultureInfo.CurrentUICulture,
                    System.Windows.FlowDirection.LeftToRight,
                    new Typeface("Tahoma"),
                    8,
                    Brushes.Black),
                new Point(ViewportHorizontalOffset, ActualHeight) + new Vector(0, -10));

            // generate samples
            double        scale   = 0.1;
            List <double> samples = new List <double>();

            for (double x = ViewportHorizontalOffset; x < ViewportHorizontalOffset + ViewportWidth; x++)
            {
                samples.Add(Math.Sin(x * scale));
            }
            Debug.WriteLine("Samples: " + samples.Count);

            if (!samples.Any())
            {
                return;
            }

            switch (renderMode)
            {
            case SineRenderMode.DirectTransformless:
                drawingContext.DrawGeometry(null, new Pen(Brushes.BlueViolet, 1), CreateGeometryTransformless(samples));
                break;

            case SineRenderMode.Direct:
                drawingContext.DrawGeometry(null, new Pen(Brushes.BlueViolet, 1), CreateGeometry(samples));
                break;

            case SineRenderMode.BitmapTransformless:
                BitmapSource bmp  = RenderBitmapTransformless(samples);
                Rect         rect = new Rect(ViewportHorizontalOffset, 0, bmp.PixelWidth, bmp.PixelHeight);
                drawingContext.DrawImage(bmp, rect);
                break;
            }
        }
Exemple #47
0
        public override object Resize(object handle, double width, double height)
        {
            var oldImg = (SWMI.BitmapSource)handle;

            width  = WidthToDPI(oldImg, width);
            height = HeightToDPI(oldImg, height);

            SWM.DrawingVisual visual = new SWM.DrawingVisual();
            using (SWM.DrawingContext ctx = visual.RenderOpen())
            {
                ctx.DrawImage(oldImg, new System.Windows.Rect(0, 0, width, height));
            }

            SWMI.RenderTargetBitmap bmp = new SWMI.RenderTargetBitmap((int)width, (int)height, oldImg.DpiX, oldImg.DpiY, oldImg.Format);
            bmp.Render(visual);

            return(bmp);
        }
Exemple #48
0
        public override object Crop(object handle, int srcX, int srcY, int w, int h)
        {
            var oldImg = (SWMI.BitmapSource)handle;

            double width  = WidthToDPI(oldImg, w);
            double height = HeightToDPI(oldImg, h);

            SWM.DrawingVisual visual = new SWM.DrawingVisual();
            using (SWM.DrawingContext ctx = visual.RenderOpen())
            {
                //Not sure whether this actually works, untested
                ctx.DrawImage(oldImg, new System.Windows.Rect(-srcX, -srcY, srcX + width, srcY + height));
            }

            SWMI.RenderTargetBitmap bmp = new SWMI.RenderTargetBitmap((int)width, (int)height, oldImg.DpiX, oldImg.DpiY, oldImg.Format);
            bmp.Render(visual);

            return(bmp);
        }
Exemple #49
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            RotaryKnob rotary = Visual as RotaryKnob;

            if (rotary != null)
            {
                drawingContext.PushTransform(new RotateTransform(rotary.KnobRotation, _center.X, _center.Y));
                drawingContext.DrawImage(_image, _imageRect);
                if (rotary.VisualizeDragging)
                {
                    double length = (rotary.DragPoint - _center).Length;
                    drawingContext.DrawLine(HeadingPen, _center, _center + new Vector(0d, -length));
                }
                drawingContext.Pop();

                if (rotary.VisualizeDragging)
                {
                    drawingContext.DrawLine(DragPen, _center, rotary.DragPoint);
                }
            }
        }
        /// <summary>
        /// Called to draw on screen
        /// </summary>
        /// <param name="drawingContext">The drawind context in which we can draw</param>
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            lock (_fireGenLock)
            {
                if (_fireGenerator == null)
                {
                    return;
                }

                // only set the pallette once (dont do in constructor as causes odd errors if exception occurs)
                if (_pallette == null)
                {
                    _pallette = SetupFirePalette();
                }

                _fireGenerator.FadeFactor = FadeFactor;
                _fireGenerator.UpdateFire();

                BitmapSource bs = BitmapSource.Create(_fireGenerator.Width, _fireGenerator.Height, DPI, DPI,
                                                      PixelFormats.Indexed8, _pallette, _fireGenerator.FireData, _fireGenerator.Width);
                drawingContext.DrawImage(bs, new Rect(0, 0, this.ActualWidth, this.ActualHeight));
            }
        }
Exemple #51
0
        public void Draw(ApplicationContext actx, SWM.DrawingContext dc, double scaleFactor, double x, double y, ImageDescription idesc)
        {
            if (drawCallback != null)
            {
                DrawingContext c = new DrawingContext(dc, scaleFactor);
                actx.InvokeUserCode(delegate {
                    drawCallback(c, new Rectangle(x, y, idesc.Size.Width, idesc.Size.Height), idesc, actx.Toolkit);
                });
            }
            else
            {
                if (idesc.Alpha < 1)
                {
                    dc.PushOpacity(idesc.Alpha);
                }

                var f        = GetBestFrame(actx, scaleFactor, idesc.Size.Width, idesc.Size.Height, false);
                var bmpImage = f as BitmapSource;

                // When an image is a single bitmap that doesn't have the same intrinsic size as the drawing size, dc.DrawImage makes a very poor job of down/up scaling it.
                // Thus we handle this manually by using a TransformedBitmap to handle the conversion in a better way when it's needed.

                var scaledWidth  = idesc.Size.Width * scaleFactor;
                var scaledHeight = idesc.Size.Height * scaleFactor;
                if (bmpImage != null && (Math.Abs(bmpImage.PixelHeight - scaledHeight) > 0.001 || Math.Abs(bmpImage.PixelWidth - scaledWidth) > 0.001))
                {
                    f = new TransformedBitmap(bmpImage, new ScaleTransform(scaledWidth / bmpImage.PixelWidth, scaledHeight / bmpImage.PixelHeight));
                }

                dc.DrawImage(f, new Rect(x, y, idesc.Size.Width, idesc.Size.Height));

                if (idesc.Alpha < 1)
                {
                    dc.Pop();
                }
            }
        }
        /// <summary>
        /// Draws the content of a <see cref="T:System.Windows.Media.DrawingContext" /> object during the render pass of a <see cref="T:System.Windows.Controls.Panel" /> element.
        /// </summary>
        /// <param name="dc">The <see cref="T:System.Windows.Media.DrawingContext" /> object to draw.</param>
        protected override void OnRender(System.Windows.Media.DrawingContext dc)
        {
            //For each face
            foreach (KeyValuePair <int, Affdex.Face> pair in Faces)
            {
                Affdex.Face face = pair.Value;

                var featurePoints = face.FeaturePoints;

                //Calculate bounding box corners coordinates.
                System.Windows.Point tl = new System.Windows.Point(featurePoints.Min(r => r.X) * XScale,
                                                                   featurePoints.Min(r => r.Y) * YScale);
                System.Windows.Point br = new System.Windows.Point(featurePoints.Max(r => r.X) * XScale,
                                                                   featurePoints.Max(r => r.Y) * YScale);

                System.Windows.Point bl = new System.Windows.Point(tl.X, br.Y);

                //Draw Points
                if (DrawPoints)
                {
                    foreach (var point in featurePoints)
                    {
                        dc.DrawEllipse(pointBrush, null, new System.Windows.Point(point.X * XScale, point.Y * YScale), fpRadius, fpRadius);
                    }

                    //Draw BoundingBox
                    dc.DrawRectangle(null, boundingPen, new System.Windows.Rect(tl, br));
                }

                //Draw Metrics
                if (DrawMetrics)
                {
                    double padding = (bl.Y - tl.Y) / MetricNames.Count;
                    double startY  = tl.Y - padding;
                    foreach (string metric in MetricNames)
                    {
                        double       width  = maxTxtWidth;
                        double       height = maxTxtHeight;
                        float        value  = -1;
                        PropertyInfo info;
                        if ((info = face.Expressions.GetType().GetProperty(NameMappings(metric))) != null)
                        {
                            value = (float)info.GetValue(face.Expressions, null);
                        }
                        else if ((info = face.Emotions.GetType().GetProperty(NameMappings(metric))) != null)
                        {
                            value = (float)info.GetValue(face.Emotions, null);
                        }

                        SolidColorBrush metricBrush = value > 0 ? pozMetricBrush : negMetricBrush;
                        value = Math.Abs(value);
                        SolidColorBrush txtBrush = value > 1 ? emojiBrush : boundingBrush;

                        double x           = tl.X - width - margin;
                        double y           = startY += padding;
                        double valBarWidth = width * (value / 100);

                        if (value > 1)
                        {
                            dc.DrawRectangle(null, boundingPen, new System.Windows.Rect(x, y, width, height));
                        }
                        dc.DrawRectangle(metricBrush, null, new System.Windows.Rect(x, y, valBarWidth, height));

                        FormattedText metricFTScaled = new FormattedText((String)upperConverter.Convert(metric, null, null, null),
                                                                         System.Globalization.CultureInfo.CurrentCulture,
                                                                         System.Windows.FlowDirection.LeftToRight,
                                                                         metricTypeFace, metricFontSize * width / maxTxtWidth, txtBrush);

                        dc.DrawText(metricFTScaled, new System.Windows.Point(x, y));
                    }
                }


                //Draw Emoji
                if (DrawEmojis)
                {
                    if (face.Emojis.dominantEmoji != Affdex.Emoji.Unknown)
                    {
                        BitmapImage          img      = emojiImages[face.Emojis.dominantEmoji];
                        double               imgRatio = ((br.Y - tl.Y) * 0.3) / img.Width;
                        System.Windows.Point tr       = new System.Windows.Point(br.X + margin, tl.Y);
                        dc.DrawImage(img, new System.Windows.Rect(tr.X, tr.Y, img.Width * imgRatio, img.Height * imgRatio));
                    }
                }

                //Draw Appearance metrics
                if (DrawAppearance)
                {
                    BitmapImage img      = appImgs[ConcatInt((int)face.Appearance.Gender, (int)face.Appearance.Glasses)];
                    double      imgRatio = ((br.Y - tl.Y) * 0.3) / img.Width;
                    double      imgH     = img.Height * imgRatio;
                    dc.DrawImage(img, new System.Windows.Rect(br.X + margin, br.Y - imgH, img.Width * imgRatio, imgH));
                }
            }



            //base.OnRender(dc);
        }
Exemple #53
0
 protected override void OnRender(System.Windows.Media.DrawingContext dc)
 {
     dc.DrawImage(CanvasImageSource, new Rect(this.RenderSize));
     base.OnRender(dc);
 }
Exemple #54
0
 public void DrawImage(ImageSource image, double x, double y, double width, double height)
 {
     g.DrawImage(image, new Rect(x, y, width, height));
 }
Exemple #55
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            Rect bounds = new Rect(0, 0, Width, Height);

            drawingContext.DrawImage(this.imageSource, bounds);
        }
Exemple #56
0
        public void Draw(System.Windows.Media.DrawingContext dc, HorizontalPhysicalAxis hAxis, VerticalPhysicalAxis vAxis)
        {
            double worldHorizontalRange    = hAxis.Axis.WorldMax - hAxis.Axis.WorldMin;
            double worldVerticalRange      = vAxis.Axis.WorldMax - vAxis.Axis.WorldMin;
            double physicalHorizontalRange = Math.Abs(hAxis.PhysicalMaxX - hAxis.PhysicalMinX);
            double physicalVerticalRange   = Math.Abs(vAxis.PhysicalMaxY - vAxis.PhysicalMinY);

            double worldBoxWidth     = worldHorizontalRange / _internalGridSize.Columns;
            double worldBoxHeight    = worldVerticalRange / _internalGridSize.Rows;
            double physicalBoxWidth  = physicalHorizontalRange / _internalGridSize.Columns + 1.0;
            double physicalBoxHeight = physicalVerticalRange / _internalGridSize.Rows + 1.0;

            byte[] img = new byte[_internalGridSize.Rows * _internalGridSize.Columns * 4];
            for (int i = 0; i < _internalGridSize.Rows; ++i)
            {
                for (int j = 0; j < _internalGridSize.Columns; ++j)
                {
                    double worldY = (double)i / (double)(_internalGridSize.Rows) * worldVerticalRange + vAxis.Axis.WorldMin + worldBoxHeight / 2.0;
                    double worldX = (double)j / (double)(_internalGridSize.Columns) * worldHorizontalRange + hAxis.Axis.WorldMin + worldBoxWidth / 2.0;
                    double val    = FieldMethod(worldX, worldY);

                    int ind = -1;
                    for (int k = 0; k < _gradientStops.Count; ++k)
                    {
                        if (_gradientStops[k].First > val)
                        {
                            ind = k;
                            break;
                        }
                    }

                    Color c;
                    if (ind == -1)
                    {
                        c = _gradientStops[_gradientStops.Count - 1].Second;
                    }
                    else if (ind == 0)
                    {
                        c = _gradientStops[0].Second;
                    }
                    else
                    {
                        Color  c1  = _gradientStops[ind - 1].Second;
                        double gv1 = _gradientStops[ind - 1].First;
                        Color  c2  = _gradientStops[ind].Second;
                        double gv2 = _gradientStops[ind].First;
                        System.Diagnostics.Debug.Assert(val >= gv1 && val < gv2);
                        double prop = (val - gv1) / (gv2 - gv1);
                        c = Color.FromRgb(
                            (byte)(c1.R * (1.0 - prop) + c2.R * prop),
                            (byte)(c1.G * (1.0 - prop) + c2.G * prop),
                            (byte)(c1.B * (1.0 - prop) + c2.B * prop));
                    }

                    img[(_internalGridSize.Rows - 1 - i) * _internalGridSize.Columns * 4 + j * 4]     = c.R;
                    img[(_internalGridSize.Rows - 1 - i) * _internalGridSize.Columns * 4 + j * 4 + 1] = c.G;
                    img[(_internalGridSize.Rows - 1 - i) * _internalGridSize.Columns * 4 + j * 4 + 2] = c.B;
                }
            }
            BitmapSource bs = BitmapSource.Create(_internalGridSize.Columns, _internalGridSize.Rows, 96, 96, PixelFormats.Bgr32, null, img, _internalGridSize.Columns * 4);

            dc.DrawImage(bs, new Rect(hAxis.PhysicalMinX, vAxis.PhysicalMaxY, physicalHorizontalRange, physicalVerticalRange));

            /*
             * for (int i = 0; i < _internalGridSize.Rows; ++i)
             * {
             *  for (int j = 0; j < _internalGridSize.Columns; ++j)
             *  {
             *      double worldY = (double)i / (double)(_internalGridSize.Rows) * worldVerticalRange + vAxis.Axis.WorldMin + worldBoxHeight / 2.0;
             *      double worldX = (double)j / (double)(_internalGridSize.Columns) * worldHorizontalRange + hAxis.Axis.WorldMin + worldBoxWidth / 2.0;
             *
             *      Color c = Color.FromRgb(0, 0, 0);
             *      for (int k = 0; k < _gradientStops.Count; ++k)
             *      {
             *          if (_gradientStops[k].First > FieldMethod(worldX, worldY))
             *          {
             *              break;
             *          }
             *          c = _gradientStops[k].Second;
             *      }
             *
             *      dc.DrawRectangle(b, null,
             *          new Rect(
             *              hAxis.WorldToPhysical(worldX, ClippingType.Clip) - physicalBoxWidth / 2.0,
             *              vAxis.WorldToPhysical(worldY, ClippingType.Clip) - physicalBoxHeight / 2.0,
             *              physicalBoxWidth, physicalBoxHeight));
             *
             *  }
             * }
             */
        }
Exemple #57
0
        private void DrawFrame(System.Windows.Media.DrawingContext drawingContext, ImageSource[] images, Int32Rect contentRect)
        {
            if (ActualWidth == 0 || ActualHeight == 0)
            {
                return;
            }
            Rect   drawRect   = new Rect(new Point(), new Size(contentRect.X, contentRect.Y));
            double drawWidth  = ActualWidth - ClipPadding.Left - ClipPadding.Right;
            double drawHeight = ActualHeight - ClipPadding.Top - ClipPadding.Bottom;

            if (drawWidth < 0 || drawHeight < 0)
            {
                return;
            }
            if (images[0] != null)
            {
                drawingContext.DrawImage(images[0], drawRect);
            }

            drawRect.X    += drawRect.Width;
            drawRect.Width = drawWidth;
            if (images[1] != null)
            {
                drawingContext.DrawImage(images[1], drawRect);
            }
            //for (int i = (int)drawRect.X; i < ActualWidth - contentRect.Width - contentRect.X; i += contentRect.Width)
            //{
            //    drawRect.X += drawRect.Width;
            //    drawRect.Width = contentRect.Width;
            //    drawingContext.DrawImage(images[1], drawRect);
            //}
            drawRect.X    += drawRect.Width;
            drawRect.Width = ClipPadding.Right;
            if (images[2] != null)
            {
                drawingContext.DrawImage(images[2], drawRect);
            }
            //中间

            drawRect.X      = 0;
            drawRect.Y      = contentRect.Y;
            drawRect.Width  = contentRect.X;
            drawRect.Height = drawHeight;
            if (images[3] != null)
            {
                drawingContext.DrawImage(images[3], drawRect);
            }

            drawRect.X    += drawRect.Width;
            drawRect.Width = drawWidth;
            if (images[4] != null)
            {
                drawingContext.DrawImage(images[4], drawRect);
            }

            drawRect.X    += drawRect.Width;
            drawRect.Width = ClipPadding.Right;
            if (images[5] != null)
            {
                drawingContext.DrawImage(images[5], drawRect);
            }

            //下边
            drawRect.X      = 0;
            drawRect.Y      = ActualHeight - ClipPadding.Bottom;
            drawRect.Width  = ClipPadding.Left;
            drawRect.Height = ClipPadding.Bottom;
            if (images[6] != null)
            {
                drawingContext.DrawImage(images[6], drawRect);
            }

            drawRect.X    += drawRect.Width;
            drawRect.Width = drawWidth;
            if (images[7] != null)
            {
                drawingContext.DrawImage(images[7], drawRect);
            }

            drawRect.X    += drawRect.Width;
            drawRect.Width = ClipPadding.Right;
            if (images[8] != null)
            {
                drawingContext.DrawImage(images[8], drawRect);
            }
        }
 protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
 {
     drawingContext.DrawImage(DragImage, new Rect(OffsetX, OffsetY, DragImage.Width, DragImage.Height));
 }
 protected override void OnRender(System.Windows.Media.DrawingContext dc)
 {
     dc.DrawImage(imgSource, new System.Windows.Rect(0, 0, imgSource.Width, imgSource.Height));
 }
Exemple #60
0
 protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
 {
     drawingContext.DrawImage(image_source, new Rect(0, 0, ActualWidth, ActualHeight));
 }