當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。