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


C# DrawingContext.DrawImage方法代码示例

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


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

示例1: Render

        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));
            }
        }
开发者ID:Core2D,项目名称:Core2D,代码行数:26,代码来源:SkiaView.cs

示例2: Draw

        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;
            }
        }
开发者ID:JuliettAlex,项目名称:Sales,代码行数:28,代码来源:ImageProviderBase.cs

示例3: DrawTile

 protected override void DrawTile(DrawingContext dc, Rect TileRect)
 {
     if (!_tileImage.IsReady)
         dc.DrawRectangle(Brushes.LemonChiffon, null, TileRect);
     else
         dc.DrawImage(_tileImage.Image, TileRect);
 }
开发者ID:NpoSaut,项目名称:netMapViewControlLib,代码行数:7,代码来源:MapImageTileElement.cs

示例4: OnRender

 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;
         }
     }
 }
开发者ID:Heliflyer,项目名称:helios,代码行数:30,代码来源:GuardedToggleSwitchRenderer.cs

示例5: OnRender

 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;
         }
     }
 }
开发者ID:Heliflyer,项目名称:helios,代码行数:30,代码来源:ToggleSwitchRenderer.cs

示例6: OnRender

        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();
            }
        }
开发者ID:Heliflyer,项目名称:helios,代码行数:28,代码来源:PushButtonRenderer.cs

示例7: OnRender

        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));
        }
开发者ID:Tesserex,项目名称:C--MegaMan-Engine,代码行数:31,代码来源:TileScreenLayer.cs

示例8: OnRender

        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));
        }
开发者ID:Core2D,项目名称:SkiaSharp,代码行数:30,代码来源:SkiaControl.cs

示例9: OnRender

        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));
        }
开发者ID:NpoSaut,项目名称:netFirmwaring,代码行数:30,代码来源:ImageScroller.cs

示例10: drawLimb

		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();
		}
开发者ID:SimonWallner,项目名称:uit2012-lab4,代码行数:31,代码来源:Sprite.cs

示例11: DrawImageOperations

 private void DrawImageOperations(DrawingContext drawingContext, IEnumerable<DrawingOperation> opeations)
 {
     foreach (var oper in opeations)
     {
         drawingContext.DrawImage(oper.Image, oper.DestRect);
     }
 }
开发者ID:CarzyCarry,项目名称:Tomato.Media,代码行数:7,代码来源:TileUnitModel.cs

示例12: Draw

        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);
            }
        }
开发者ID:SpoinkyNL,项目名称:Artemis,代码行数:25,代码来源:KeyboardGifType.cs

示例13: OnRender

 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)));
     }
 }
开发者ID:Yariki,项目名称:ShareScreen,代码行数:8,代码来源:SSScreenShotCanvas.cs

示例14: draw

 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);
 }
开发者ID:davidboyd96,项目名称:Bits-Please--FINAL,代码行数:8,代码来源:BasketballManager.cs

示例15: OnRender

        /// <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));
        }
开发者ID:VitalyKalinkin,项目名称:ICFP,代码行数:13,代码来源:BitmapCanvas.xaml.cs


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