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


C# CanvasDrawingSession.DrawImage方法代码示例

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


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

示例1: DrawIcon

        // Alternative entrypoint for use by AppIconGenerator.
        internal void DrawIcon(CanvasDrawingSession drawingSession, string text)
        {
            this.text = text;
            this.fontSize = 64;

            CreateFlameEffect();
            SetupText(drawingSession);
            ConfigureEffect(new CanvasTimingInformation());

            drawingSession.DrawImage(flamePosition);
            drawingSession.DrawImage(textCommandList);
        }
开发者ID:jiatingxiu,项目名称:Win2D,代码行数:13,代码来源:BurningTextExample.xaml.cs

示例2: Draw

        //int count;
        public void Draw(CanvasDrawingSession ds, Size sizeRender, float totalTimeSeconds)
        {
            //count++;
            //ds.DrawText(count.ToString(), new Vector2(10.0f, 10.0f), Colors.Red);
            SetupText(ds);
            ConfigureEffect(totalTimeSeconds);

            ds.DrawImage(composite, sizeRender.ToVector2() / 2);
        }
开发者ID:clarkezone,项目名称:BUILD2015-Talk-2-672,代码行数:10,代码来源:BurningTextExample.xaml.cs

示例3: ApplyBloomFilter

        void ApplyBloomFilter(CanvasDrawingSession drawingSession)
        {
            // Configure effects to use the latest threshold, blur, and intensity settings.
            extractBrightAreas.RedSlope =
            extractBrightAreas.GreenSlope =
            extractBrightAreas.BlueSlope = 1 / (1 - BloomThreshold / 100);

            extractBrightAreas.RedOffset =
            extractBrightAreas.GreenOffset =
            extractBrightAreas.BlueOffset = -BloomThreshold / 100 / (1 - BloomThreshold / 100);

            blurBrightAreas.BlurAmount = BloomBlur;

            adjustBloomIntensity.RedSlope =
            adjustBloomIntensity.GreenSlope =
            adjustBloomIntensity.BlueSlope = BloomIntensity / 100;

            // Apply the bloom effect.
            drawingSession.DrawImage(bloomResult);
        }
开发者ID:zlvb,项目名称:Win2D-Samples,代码行数:20,代码来源:Direct3DInteropExample.xaml.cs

示例4: Draw

        // Draws all of the active particles.
        public void Draw(CanvasDrawingSession drawingSession)
        {
            var previousBlend = drawingSession.Blend;

            drawingSession.Blend = blendState;

            // Go through the particles in reverse order, so new ones are drawn underneath
            // older ones. This improves visual appearance of effects like smoke plume
            // where many particles are created at the same position over a period of time.
            for (int i = activeParticles.Count - 1; i >= 0; i--)
            {
                Particle particle = activeParticles[i];

                // Normalized lifetime is a value from 0 to 1 and represents how far a particle
                // is through its life. 0 means it just started, .5 is half way through, and
                // 1.0 means it's just about to be finished. This value will be used to calculate
                // alpha and scale, to avoid  having particles suddenly appear or disappear.
                float normalizedLifetime = particle.TimeSinceStart / particle.Lifetime;

                // We want particles to fade in and fade out, so we'll calculate alpha to be
                // (normalizedLifetime) * (1 - normalizedLifetime). This way, when normalizedLifetime
                // is 0 or 1, alpha is 0. The maximum value is at normalizedLifetime = .5, and is:
                //
                //      (normalizedLifetime) * (1-normalizedLifetime)
                //      (.5)                 * (1-.5)
                //      .25
                //
                // Since we want the maximum alpha to be 1, not .25, we'll scale the entire equation by 4.
                float alpha = 4 * normalizedLifetime * (1 - normalizedLifetime);

                // Make particles grow as they age.
                // They'll start at 75% of their size, and increase to 100% once they're finished.
                float scale = particle.Scale * (.75f + .25f * normalizedLifetime);

                // Compute a transform matrix for this particle.
                var transform = Matrix3x2.CreateRotation(particle.Rotation, bitmapCenter) *
                                Matrix3x2.CreateScale(scale, bitmapCenter) *
                                Matrix3x2.CreateTranslation(particle.Position - bitmapCenter);

                // Draw the particle.
                drawingSession.DrawImage(bitmap, 0, 0, bitmapBounds, alpha, CanvasImageInterpolation.Linear, new Matrix4x4(transform));
            }

            drawingSession.Blend = previousBlend;
        }
开发者ID:liuywg,项目名称:Win2D-Samples,代码行数:46,代码来源:ParticleSystem.cs

示例5: Draw

        public void Draw(CanvasDrawingSession drawingSession)
        {
            // 保护原先画布的混合模式
            var previousBlend = drawingSession.Blend;

            drawingSession.Blend = CanvasBlend.SourceOver;
            // Compute a transform matrix for this particle.
            if (canDraw)
            {
                var transform = Matrix3x2.CreateScale(scale.X, scale.Y, center) *
                    Matrix3x2.CreateTranslation(position - center);
                if (blurFrame != 0)
                    drawingSession.DrawImage(blur, new Rect(position.X - (bound.Width * scale.X) / 2, position.Y - (bound.Height * scale.Y) / 2, bound.Width * scale.X, bound.Height * scale.Y), bound, opacity);
                else
                    drawingSession.DrawImage(tempSurface, 0f, 0f, bound, opacity, CanvasImageInterpolation.Linear, new Matrix4x4(transform));
            }
            drawingSession.Blend = previousBlend;
        }
开发者ID:aurora-lzzp,项目名称:Aurora-Weather,代码行数:18,代码来源:BGBlur.cs

示例6: Draw

        protected virtual void Draw(CanvasDrawingSession drawingSession
#if WINDOWS_UWP
            , CanvasSpriteBatch spriteBatch
#endif
            )
        {
            // 逆向遍历队列,可以让新粒子绘制在旧粒子下方,这样当很多粒子在同一个位置生成时,效果较好
            for (int i = activeParticles.Count - 1; i >= 0; i--)
            {
                Particle particle = activeParticles[i];

                // NormalizedLifeTime 是一个0到1之间的值,用来表示粒子在生命周期中的进度,这个值接近0或接近1时,
                // 粒子将会渐隐/渐显,使用它来计算粒子的透明度和缩放
                //float normalizedLifetime = particle.TimeSinceStart / particle.Lifetime;

                // We want particles to fade in and fade out, so we'll calculate alpha to be
                // (normalizedLifetime) * (1 - normalizedLifetime). This way, when normalizedLifetime
                // is 0 or 1, alpha is 0. The maximum value is at normalizedLifetime = .5, and is:
                //
                //      (normalizedLifetime) * (1-normalizedLifetime)
                //      (.5)                 * (1-.5)
                //      .25
                //
                // Since we want the maximum alpha to be 1, not .25, we'll scale the entire equation by 4.
                //float alpha = 4 * normalizedLifetime * (1 - normalizedLifetime);

                // Make particles grow as they age.
                // They'll start at 75% of their size, and increase to 100% once they're finished.
                //float scale = particle.Scale * (.75f + .25f * normalizedLifetime);

#if WINDOWS_UWP
                if (spriteBatch != null)
                {
                    spriteBatch.Draw(bitmap, particle.Position, new Vector4(1, 1, 1, 1/*alpha*/), bitmapCenter,
                        particle.Rotation - 1.5708f, new Vector2(particle.ScaleX, particle.ScaleY/*scale*/), CanvasSpriteFlip.None);
                }
                else
#endif
                {
                    // Compute a transform matrix for this particle.
                    var transform = Matrix3x2.CreateRotation(particle.Rotation - 1.5708f, bitmapCenter) *
                                    Matrix3x2.CreateScale(/*scale*/particle.ScaleX, particle.ScaleY, bitmapCenter) *
                                    Matrix3x2.CreateTranslation(particle.Position - bitmapCenter);

                    // Draw the particle.
                    drawingSession.DrawImage(bitmap, 0, 0, bitmapBounds, 1/*alpha*/, CanvasImageInterpolation.Linear, new Matrix4x4(transform));
                }
            }
        }
开发者ID:aurora-lzzp,项目名称:Aurora-Weather,代码行数:49,代码来源:ParticleSystem.cs

示例7: Draw

        public void Draw(ICanvasAnimatedControl sender, CanvasDrawingSession drawingSession)
        {
            if (currentThunder == null)
            {
                return;
            }
            // 保护原先画布的混合模式
            var previousBlend = drawingSession.Blend;
            drawingSession.Blend = blendState;
            var builder = new CanvasPathBuilder(sender);
            builder.BeginFigure(0, 0);
            for (int i = 0; i < currentThunder.LifeLong; i++)
            {
                builder.AddLine(currentThunder.Path[i].X, currentThunder.Path[i].Y);
            }
            builder.EndFigure(CanvasFigureLoop.Open);
            builder.SetSegmentOptions(CanvasFigureSegmentOptions.ForceRoundLineJoin);

            // Draw the particle.
            var path = CanvasGeometry.CreatePath(builder);
            var NormalizeLifeTime = currentThunder.TimeSinceStart / currentThunder.Duration;
            byte opacity = (byte)((NormalizeLifeTime - 1) * (NormalizeLifeTime - 1) * 255);
            CanvasCommandList cl = new CanvasCommandList(sender);
            using (CanvasDrawingSession clds = cl.CreateDrawingSession())
            {
                clds.DrawGeometry(path, currentThunder.Position, Color.FromArgb((byte)(0.75f * opacity), 255, 255, 255), 6 * currentThunder.Luminace);
            }
            var lightAmount = 20.6f * currentThunder.Luminace * (NormalizeLifeTime - 1) * (NormalizeLifeTime - 1);
            blur.Source = cl;
            blur.BlurAmount = lightAmount;
            drawingSession.DrawImage(blur);
            drawingSession.DrawGeometry(path, currentThunder.Position, Color.FromArgb(opacity, 255, 240, 180), 2 * currentThunder.Luminace);
            drawingSession.Blend = previousBlend;
            if (NormalizeLifeTime > 1)
            {
                currentThunder = null;
            }
        }
开发者ID:aurora-lzzp,项目名称:Aurora-Weather,代码行数:38,代码来源:ThunderGenerator.cs

示例8: Draw

            public void Draw(CanvasDrawingSession ds, int frameCounter, float width, float height)
            {
                var sz = sourceBitmap.Size;
                Rect sourceRect = new Rect(
                    sz.Width * 0.25 + Math.Sin(frameCounter * 0.02) * (sz.Width * 0.5),
                    sz.Height * 0.25 + Math.Cos(frameCounter * 0.01) * (sz.Height * 0.5),
                    sz.Width * 0.5,
                    sz.Height * 0.5);

                double y = DrawSourceImage(ds, sourceRect, width);

                double displayWidth = width / 2;
                double x = displayWidth;
                double destHeight = (height - y) / 3;

                Rect bitmapDestRect = new Rect(x, y + 5, displayWidth, destHeight - 10);
                y += destHeight;

                Rect bitmapDestRect2 = new Rect(x, y + 5, displayWidth, destHeight - 10);
                y += destHeight;

                Rect effectDestRect = new Rect(x, y + 5, displayWidth, destHeight - 10);

                var format = new CanvasTextFormat()
                {
                    FontSize = 14,
                    HorizontalAlignment = CanvasHorizontalAlignment.Right,
                    VerticalAlignment = CanvasVerticalAlignment.Center
                };

                ds.DrawText("D2D DrawBitmap", 0, (float)bitmapDestRect.Y, (float)displayWidth - 10, (float)destHeight, Colors.White, format);
                ds.DrawText("D2D DrawImage (bitmap)", 0, (float)bitmapDestRect2.Y, (float)displayWidth - 10, (float)destHeight, Colors.White, format);
                ds.DrawText("D2D DrawImage (effect)", 0, (float)effectDestRect.Y, (float)displayWidth - 10, (float)destHeight, Colors.White, format);

                ds.FillRectangle(bitmapDestRect, fillPattern);
                ds.FillRectangle(bitmapDestRect2, fillPattern);
                ds.FillRectangle(effectDestRect, fillPattern);

                ds.DrawImage(sourceBitmap, bitmapDestRect, sourceRect);
                ds.DrawImage(sourceBitmap, bitmapDestRect2, sourceRect, 1, CanvasImageInterpolation.Cubic);
                ds.DrawImage(sourceEffect, effectDestRect, sourceRect);

                ds.DrawRectangle(bitmapDestRect, Colors.Yellow, 1, hairline);
                ds.DrawRectangle(bitmapDestRect2, Colors.Yellow, 1, hairline);
                ds.DrawRectangle(effectDestRect, Colors.Yellow, 1, hairline);
            }
开发者ID:fengweijp,项目名称:Win2D,代码行数:46,代码来源:DrawImageEmulations.xaml.cs

示例9: DoUIElementsEffect

        private void DoUIElementsEffect(CanvasControl sender, CanvasDrawingSession ds)
        {
            foreach (var elm in _uielements)
            {
                var offset = (float)ExpandAmount / 2;
                using (var cl = new CanvasCommandList(ds))
                {
                    using (var clds = cl.CreateDrawingSession())
                    {
                        using (var canvasbmp = CanvasBitmap.CreateFromBytes(sender.Device, elm.Item1, elm.Item2, elm.Item3, Windows.Graphics.DirectX.DirectXPixelFormat.B8G8R8A8UIntNormalized))
                        {
                            clds.DrawImage(canvasbmp, 0, 0);
                        }

                    }

                    _eg.Setup(cl, (float)GlowAmount, GlowColor);
                    ds.DrawImage(_eg.Output, offset + (float)elm.Item4, offset + (float)elm.Item5);
                }
              
            }
            
        }
开发者ID:liquidboy,项目名称:X,代码行数:23,代码来源:EffectLayer.cs

示例10: DoPathEffect

        private void DoPathEffect(CanvasControl sender, CanvasDrawingSession ds )
        {    
            using (var thBuilder = new Microsoft.Graphics.Canvas.Geometry.CanvasPathBuilder(sender))
            {
                var pthConverter = new PathToD2DPathGeometryConverter();

                foreach(var path in _paths)
                {
                    var offset = (float)ExpandAmount / 2;
                    using (var cl = new CanvasCommandList(ds))
                    using (var pthGeo = pthConverter.parse(path, thBuilder))
                    {
                        using (var clds = cl.CreateDrawingSession())
                        {
                            clds.FillGeometry(pthGeo,0,0, GlowColor);
                        }

                        _eg.Setup(cl, (float)GlowAmount, GlowColor);
                        ds.DrawImage(_eg.Output, offset, offset);
                        ds.FillGeometry(pthGeo,offset, offset, ((SolidColorBrush)GlowFill).Color);
                    }
                    
                }

            }
        }
开发者ID:liquidboy,项目名称:X,代码行数:26,代码来源:EffectLayer.cs

示例11: DrawToOutput

        void DrawToOutput(PerDeviceResources resources, CanvasDrawingSession ds)
        {
            if (CurrentIntermediate == IntermediateMode.None)
            {
                // We can either draw directly to the output...
                DrawSourceGraphic(resources, ds, testOffset);
            }
            else
            {
                // Or go via an intermediate such as a rendertarget or image effect.
                var intermediateImage = WrapSourceWithIntermediateImage(resources, CurrentIntermediate);

                ds.DrawImage(intermediateImage, testOffset, testOffset);
            }

            resources.AddMessage("{0} (dpi: {1})", CurrentOutput, ds.Dpi);
        }
开发者ID:fengweijp,项目名称:Win2D,代码行数:17,代码来源:DpiExample.xaml.cs

示例12: DrawSourceGraphic

        void DrawSourceGraphic(PerDeviceResources resources, CanvasDrawingSession ds, float offset)
        {
            var source = GetSourceBitmap(resources);

            if (source != null)
            {
                // We can either draw a precreated bitmap...
                ds.DrawImage(source, offset, offset);
            }
            else
            {
                // ... or directly draw some shapes.
                ds.FillRectangle(offset, offset, testSize, testSize, Colors.Gray);

                ds.DrawLine(offset, offset, offset + testSize, offset + testSize, Colors.Red);
                ds.DrawLine(offset + testSize, offset, offset, offset + testSize, Colors.Red);

                ds.DrawRectangle(offset + 0.5f, offset + 0.5f, testSize - 1, testSize - 1, Colors.Blue);

                ds.DrawText("DPI test", new Vector2(offset + testSize / 2), Colors.Blue, resources.TextFormat);

                resources.AddMessage("DrawingSession ->\n");
            }
        }
开发者ID:fengweijp,项目名称:Win2D,代码行数:24,代码来源:DpiExample.xaml.cs

示例13: DrawStuff

        void DrawStuff(CanvasDrawingSession ds)
        {
            int horizontalLimit = (int)m_canvasControl.ActualWidth;
            int verticalLimit = (int)m_canvasControl.ActualHeight;
            const float thickStrokeWidth = 80.0f;

            DrawnContentType drawnContentType = (DrawnContentType)m_drawnContentTypeCombo.SelectedValue;

            ds.Clear(NextRandomColor());
                
            Rect rect;
            Vector2 point;
            float radiusX;
            float radiusY;

            switch (drawnContentType)
            {
                case DrawnContentType.Clear_Only:
                    break;

                case DrawnContentType.Bitmap:
                    if (m_bitmap_tiger != null)
                    {
                        ds.DrawImage(m_bitmap_tiger, NextRandomPoint(horizontalLimit, verticalLimit).ToVector2());
                    }
                    else
                    {
                        DrawNoBitmapErrorMessage(ds, horizontalLimit / 2, verticalLimit / 2);
                    }
                    break;

                case DrawnContentType.Effect_Blur:
                    if (m_bitmap_tiger != null)
                    {
                        GaussianBlurEffect blurEffect = new GaussianBlurEffect();
                        blurEffect.StandardDeviation = 2.0f;
                        blurEffect.Source = m_bitmap_tiger;
                        ds.DrawImage(blurEffect, NextRandomPoint(horizontalLimit, verticalLimit).ToVector2());
                    }
                    else
                    {
                        DrawNoBitmapErrorMessage(ds, horizontalLimit / 2, verticalLimit / 2);
                    }
                    break;

                case DrawnContentType.Line_Thin:
                    ds.DrawLine(
                        NextRandomPoint(horizontalLimit, verticalLimit).ToVector2(),
                        NextRandomPoint(horizontalLimit, verticalLimit).ToVector2(),
                        NextRandomColor());
                    break;

                case DrawnContentType.Line_Thick:
                    ds.DrawLine(
                        NextRandomPoint(horizontalLimit, verticalLimit).ToVector2(),
                        NextRandomPoint(horizontalLimit, verticalLimit).ToVector2(),
                        NextRandomColor(),
                        thickStrokeWidth);
                    break;

                case DrawnContentType.Rectangle_Thin:
                    ds.DrawRectangle(
                        NextRandomRect(horizontalLimit, verticalLimit),
                        NextRandomColor());
                    break;

                case DrawnContentType.Rectangle_Thick:
                    ds.DrawRectangle(
                        NextRandomRect(horizontalLimit, verticalLimit),
                        NextRandomColor(),
                        thickStrokeWidth);
                    break;

                case DrawnContentType.Rectangle_Filled:
                    ds.FillRectangle(
                        NextRandomRect(horizontalLimit, verticalLimit),
                        NextRandomColor());
                    break;

                case DrawnContentType.RoundedRectangle_Thin:
                    NextRandomRoundedRect(horizontalLimit, verticalLimit, out rect, out radiusX, out radiusY);
                    ds.DrawRoundedRectangle(
                        rect, radiusX, radiusY,
                        NextRandomColor());
                    break;

                case DrawnContentType.RoundedRectangle_Thick:
                    NextRandomRoundedRect(horizontalLimit, verticalLimit, out rect, out radiusX, out radiusY);
                    ds.DrawRoundedRectangle(
                        rect, radiusX, radiusY,
                        NextRandomColor(),
                        thickStrokeWidth);
                    break;

                case DrawnContentType.Ellipse_Thin:
                    NextRandomEllipse(horizontalLimit, verticalLimit, out point, out radiusX, out radiusY);
                    ds.DrawEllipse(
                        point, radiusX, radiusY,
                        NextRandomColor());
                    break;
//.........这里部分代码省略.........
开发者ID:gfcprogramer,项目名称:Win2D,代码行数:101,代码来源:MainPage.xaml.cs

示例14: DisplayRegionMask

        public bool DisplayRegionMask(CanvasDrawingSession drawingSession, float zoomFactor, bool editInProgress)
        {
            if (!IsEnabled || !IsEditingRegion || !ShowRegion || regionMask == null)
                return false;

            if (editInProgress && RegionSelectionOperation == SelectionOperation.Replace)
                return false;

            drawingSession.Blend = CanvasBlend.SourceOver;

            if (!editInProgress)
            {
                // Gray out everything outside the region.
                var mask = new ColorMatrixEffect
                {
                    Source = GetRegionMask(),

                    ColorMatrix = new Matrix5x4
                    {
                        // Set RGB = gray.
                        M51 = 0.5f,
                        M52 = 0.5f,
                        M53 = 0.5f,

                        // Invert and scale the mask alpha.
                        M44 = -0.75f,
                        M54 = 0.75f,
                    }
                };

                drawingSession.DrawImage(mask);
            }

            // Magenta region border.
            var border = GetSelectionBorder(regionMask, zoomFactor);

            drawingSession.DrawImage(border);

            return true;
        }
开发者ID:shawnhar,项目名称:stuart,代码行数:40,代码来源:EditGroup.cs

示例15: DisplayRegionEditInProgress

        public void DisplayRegionEditInProgress(CanvasDrawingSession drawingSession, List<Vector2> points, float zoomFactor)
        {
            if (RegionSelectionMode == SelectionMode.MagicWand)
            {
                // Display a magic wand selection.
                var mask = GetMagicWandMask(points, zoomFactor);
                var border = GetSelectionBorder(mask, zoomFactor);

                drawingSession.Blend = CanvasBlend.Add;
                drawingSession.DrawImage(mask, Vector2.Zero, SourceBitmap.Bounds, 0.25f);

                drawingSession.Blend = CanvasBlend.SourceOver;
                drawingSession.DrawImage(border);
            }
            else
            {
                // Display a geometric shape selection.
                var geometry = GetSelectionGeometry(drawingSession, points);

                drawingSession.Blend = CanvasBlend.Add;
                drawingSession.FillGeometry(geometry, Color.FromArgb(0x20, 0xFF, 0xFF, 0xFF));

                drawingSession.Blend = CanvasBlend.SourceOver;
                drawingSession.DrawGeometry(geometry, Colors.Magenta, 1f / zoomFactor);
            }
        }
开发者ID:shawnhar,项目名称:stuart,代码行数:26,代码来源:EditGroup.cs


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