Ejemplo n.º 1
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="capture">Capture object</param>
 public LinearGradientBrushElement(Capture capture)
 {
     // Set the default values
     _startPoint      = Vector2.Zero;
     _endPoint        = Vector2.Zero;
     _opacity         = 1f;
     _alphaMode       = (CanvasAlphaMode)0;
     _bufferPrecision = (CanvasBufferPrecision)0;
     _edgeBehavior    = (CanvasEdgeBehavior)0;
     // Default ColorSpace is sRGB
     _preInterpolationColorSpace  = CanvasColorSpace.Srgb;
     _postInterpolationColorSpace = CanvasColorSpace.Srgb;
     _gradientStops = new List <CanvasGradientStop>();
     // Initialize
     Initialize(capture);
 }
Ejemplo n.º 2
0
            private CanvasRenderTarget CreateSourceImage(CanvasControl sender, CanvasAlphaMode alphaMode)
            {
                var image = new CanvasRenderTarget(sender, 64, 64, sender.Dpi, DirectXPixelFormat.B8G8R8A8UIntNormalized, alphaMode);

                using (var ds = image.CreateDrawingSession())
                {
                    ds.Clear(Colors.Transparent);

                    ds.FillRectangle(0, 0, 64, 16, Colors.Blue);
                    ds.FillRectangle(0, 32 - 8, 64, 16, Color.FromArgb(128, 0, 0, 255));
                    ds.FillRectangle(0, 64 - 16, 64, 16, Colors.Blue);

                    ds.FillCircle(32, 32, 16, Colors.Yellow);
                }
                return(image);
            }
Ejemplo n.º 3
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="capture">Capture object</param>
 public RadialGradientHdrBrushElement(Capture capture)
 {
     // Set the default values
     _radiusX         = 0f;
     _radiusY         = 0f;
     _center          = Vector2.Zero;
     _originOffset    = Vector2.Zero;
     _opacity         = 1f;
     _alphaMode       = (CanvasAlphaMode)0;
     _bufferPrecision = (CanvasBufferPrecision)0;
     _edgeBehavior    = (CanvasEdgeBehavior)0;
     // Default ColorSpace is sRGB
     _preInterpolationColorSpace  = CanvasColorSpace.Srgb;
     _postInterpolationColorSpace = CanvasColorSpace.Srgb;
     _gradientStopHdrs            = new List <CanvasGradientStopHdr>();
     // Initialize
     Initialize(capture);
 }
Ejemplo n.º 4
0
        void TestCreateFromSoftwareBitmap(CanvasDevice device, BitmapPixelFormat pixelFormat, BitmapAlphaMode alphaMode)
        {
            if (pixelFormat == BitmapPixelFormat.Unknown)
            {
                return;
            }

            int anyWidth  = 3;
            int anyHeight = 5;

            var softwareBitmap = new SoftwareBitmap(pixelFormat, anyWidth, anyHeight, alphaMode);

            if (!IsFormatSupportedByWin2D(pixelFormat, alphaMode))
            {
                Assert.ThrowsException <Exception>(() =>
                {
                    CanvasBitmap.CreateFromSoftwareBitmap(device, softwareBitmap);
                });
                return;
            }

            var canvasBitmap = CanvasBitmap.CreateFromSoftwareBitmap(device, softwareBitmap);

            Assert.AreEqual(anyWidth, (int)canvasBitmap.SizeInPixels.Width);
            Assert.AreEqual(anyHeight, (int)canvasBitmap.SizeInPixels.Height);
            Assert.AreEqual(GetDirectXPixelFormatUsedForBitmapPixelFormat(pixelFormat), canvasBitmap.Format);

            CanvasAlphaMode expectedAlphaMode = CanvasAlphaMode.Straight;

            switch (alphaMode)
            {
            case BitmapAlphaMode.Ignore: expectedAlphaMode = CanvasAlphaMode.Ignore; break;

            case BitmapAlphaMode.Premultiplied: expectedAlphaMode = CanvasAlphaMode.Premultiplied; break;

            case BitmapAlphaMode.Straight: expectedAlphaMode = CanvasAlphaMode.Straight; break;
            }

            Assert.AreEqual(expectedAlphaMode, canvasBitmap.AlphaMode);
        }
Ejemplo n.º 5
0
            private CanvasRenderTarget CreateSourceImage(CanvasControl sender, CanvasAlphaMode alphaMode)
            {
                var image = new CanvasRenderTarget(sender, 64, 64, sender.Dpi, DirectXPixelFormat.B8G8R8A8UIntNormalized, alphaMode);
                
                using (var ds = image.CreateDrawingSession())
                {
                    ds.Clear(Colors.Transparent);

                    ds.FillRectangle(0, 0, 64, 16, Colors.Blue);
                    ds.FillRectangle(0, 32 - 8, 64, 16, Color.FromArgb(128, 0, 0, 255));
                    ds.FillRectangle(0, 64 - 16, 64, 16, Colors.Blue);

                    ds.FillCircle(32, 32, 16, Colors.Yellow);
                }
                return image;
            }
Ejemplo n.º 6
0
 private CanvasRenderTarget CreateTarget(CanvasControl sender, CanvasAlphaMode alphaMode)
 {
     return new CanvasRenderTarget(sender, 64, 64, sender.Dpi, DirectXPixelFormat.B8G8R8A8UIntNormalized, alphaMode);
 }
Ejemplo n.º 7
0
 private CanvasRenderTarget CreateTarget(CanvasControl sender, CanvasAlphaMode alphaMode)
 {
     return(new CanvasRenderTarget(sender, 64, 64, sender.Dpi, DirectXPixelFormat.B8G8R8A8UIntNormalized, alphaMode));
 }
Ejemplo n.º 8
0
 static void ValidateCannotCreateRenderTarget(CanvasDevice device, DirectXPixelFormat format, CanvasAlphaMode alphaMode)
 {
     ValidateUnsupportedPixelFormatException(() =>
     {
         new CanvasRenderTarget(device, 16, 16, 96, format, alphaMode);
     });
 }
Ejemplo n.º 9
0
 static void ValidateCannotCreateBitmap(CanvasDevice device, DirectXPixelFormat format, CanvasAlphaMode alphaMode)
 {
     ValidateUnsupportedPixelFormatException(() =>
     {
         CanvasBitmap.CreateFromBytes(device, new byte[1024], 4, 4, format, 96, alphaMode);
     });
 }
Ejemplo n.º 10
0
        //边缘检测方法
        public static ICanvasImage GetEdgeDetection(ICanvasImage canvasImage, float Amount, float BlurAmount = 0, EdgeDetectionEffectMode Mode = EdgeDetectionEffectMode.Sobel, CanvasAlphaMode AlphaMode = CanvasAlphaMode.Premultiplied, bool OverlayEdges = false)
        {
            if (Amount < 0)
            {
                Amount = 0;
            }
            else if (Amount > 1)
            {
                Amount = 1;
            }
            if (BlurAmount < 0)
            {
                BlurAmount = 0;
            }
            else if (BlurAmount > 10)
            {
                BlurAmount = 10;
            }

            return(new EdgeDetectionEffect
            {
                Source = canvasImage,

                Amount = Amount,
                BlurAmount = BlurAmount,

                Mode = Mode,
                AlphaMode = AlphaMode,
                OverlayEdges = OverlayEdges,
            });
        }
Ejemplo n.º 11
0
 static void ValidateCannotCreateRenderTarget(CanvasDevice device, DirectXPixelFormat format, CanvasAlphaMode alphaMode)
 {
     ValidateUnsupportedPixelFormatException(() =>
     {
         new CanvasRenderTarget(device, 16, 16, 96, format, alphaMode);
     });
 }
Ejemplo n.º 12
0
 static void ValidateCannotCreateBitmap(CanvasDevice device, DirectXPixelFormat format, CanvasAlphaMode alphaMode)
 {
     ValidateUnsupportedPixelFormatException(() =>
     {
         CanvasBitmap.CreateFromBytes(device, new byte[1024], 4, 4, format, 96, alphaMode);
     });
 }