void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            // Find coordinates to center bitmap in canvas...
            float x = (info.Width - bitmap.Width) / 2f;
            float y = (info.Height - bitmap.Height) / 2f;

            using (SKPaint paint = new SKPaint())
            {
                // ... but use them to create a translate transform
                SKMatrix matrix = SKMatrix.MakeTranslation(x, y);
                paint.Shader = SKShader.CreateBitmap(bitmap,
                                                     SKShaderTileMode.Repeat,
                                                     SKShaderTileMode.Repeat,
                                                     matrix);

                // Use that tiled bitmap pattern to fill a circle
                canvas.DrawCircle(info.Rect.MidX, info.Rect.MidY,
                                  Math.Min(info.Width, info.Height) / 2,
                                  paint);
            }
        }
        protected override void OnDrawSample(SKCanvas canvas, int width, int height)
        {
            // load the image from the embedded resource stream
            using (var stream = new SKManagedStream(SampleMedia.Images.ColorWheel))
                using (var source = SKBitmap.Decode(stream))
                {
                    // invert the pixels
                    var pixels = source.Pixels;
                    for (int i = 0; i < pixels.Length; i++)
                    {
                        pixels[i] = new SKColor(
                            (byte)(255 - pixels[i].Red),
                            (byte)(255 - pixels[i].Green),
                            (byte)(255 - pixels[i].Blue),
                            pixels[i].Alpha);
                    }
                    source.Pixels = pixels;

                    using (var shader = SKShader.CreateBitmap(source, SKShaderTileMode.Repeat, SKShaderTileMode.Repeat))
                        using (var paint = new SKPaint())
                        {
                            paint.IsAntialias = true;
                            paint.Shader      = shader;

                            // tile the bitmap
                            canvas.Clear(SKColors.White);
                            canvas.DrawPaint(paint);
                        }
                }
        }
Beispiel #3
0
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            // work out points for the path considering denisity of device
            float densityMultiplier = args.Info.Height / (float)SkiaCanvas.Height;
            var   curveAmount       = (float)CurveAmount.Value * densityMultiplier;
            float curveStart        = args.Info.Height - curveAmount;
            float curveEnd          = args.Info.Height + curveAmount;

            args.Surface.Canvas.Clear();

            // create the clipping path
            SKPath path = CreatePath(curveStart, curveEnd, args.Info.Width);

            args.Surface.Canvas.ClipPath(path, antialias: true);

            // render bitmap into clipping rectangle
            using (SKPaint paint = new SKPaint())
            {
                // Create bitmap tiling
                paint.Shader = SKShader.CreateBitmap(resourceBitmap,
                                                     SKShaderTileMode.Repeat,
                                                     SKShaderTileMode.Repeat);
                // Draw background
                args.Surface.Canvas.DrawRect(args.Info.Rect, paint);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Draw a textured background
        /// </summary>
        /// <param name="backgroundColor">the backgroud color</param>
        /// <param name="canvas">the canvas</param>
        /// <param name="bounds">the bounds</param>
        public static void DrawBackground(Color backgroundColor, SKCanvas canvas, SKRect bounds)
        {
            if (canvas == null)
            {
                throw new ArgumentNullException(nameof(canvas));
            }

            using var bitmap = new SKBitmap(128, 128);
            using (var bitmapCanvas = new SKCanvas(bitmap))
            {
                //bitmapCanvas.Clear(backgroundColor.ToSKColor());
                using var colorShader  = SKShader.CreateColor(backgroundColor.ToSKColor());
                using var perlinShader = SKShader.CreatePerlinNoiseFractalNoise(0.8f, 0.8f, 1, 1, new SKPointI(64, 64));
                using var paint        = new SKPaint
                      {
                          Color       = backgroundColor.ToSKColor(),
                          Shader      = SKShader.CreateCompose(colorShader, perlinShader),
                          IsAntialias = true,
                          IsStroke    = false
                      };
                bitmapCanvas.DrawRect(new SKRect(0, 0, 128, 128), paint);
            }

            using var paint2 = new SKPaint
                  {
                      Shader      = SKShader.CreateBitmap(bitmap, SKShaderTileMode.Repeat, SKShaderTileMode.Repeat),
                      IsStroke    = false,
                      IsAntialias = true
                  };
            canvas.Clear(Color.Transparent.ToSKColor());

            canvas.DrawRect(bounds, paint2);
        }
Beispiel #5
0
        public ColorPickerView(ContextManager mg)
        {
            manager = mg;
            InitializeComponent();
            SetBindingContext();
            StrokeWidthSlider.BindingContext = Service;
            HardnesSlider.BindingContext     = Service;

            SpacingSlider.BindingContext          = Service;
            XDispSlider.BindingContext            = Service;
            YDispSlider.BindingContext            = Service;
            OpacityRandomSlider.BindingContext    = Service;
            ScaleSlider.BindingContext            = Service;
            HueJitterSlider.BindingContext        = Service;
            SaturationJitterSlider.BindingContext = Service;
            LightnessJitterSlider.BindingContext  = Service;
            HardnessJitter.BindingContext         = Service;
            BMSelector.ItemsSource = PBlendingMode.Names;


            Assembly assembly = GetType().GetTypeInfo().Assembly;

            using (Stream strem = assembly.GetManifestResourceStream("Pen.bg.bmp"))
                using (SKManagedStream skStream = new SKManagedStream(strem))
                    using (SKBitmap bitma = SKBitmap.Decode(skStream))
                        using (SKShader shader = SKShader.CreateBitmap(bitma, SKShaderTileMode.Repeat, SKShaderTileMode.Repeat))
                        {
                            //BgPaint.Shader = shader;
                        };
            var a = manager.ActiveKernel.Get <BackgroundImage>();

            BgPaint.Shader = a.GetShader();
        }
Beispiel #6
0
        /// <summary>
        /// Create the SKPaint object for each style and store it in the requested object.
        /// </summary>
        /// <param name="tpe">the TagParserPaint object to populate</param>
        private static SKPaint SetPaintForTPP(StylePaint tpe)
        {
            var paint = new SKPaint();

            paint.StrokeJoin  = SKStrokeJoin.Round;
            paint.IsAntialias = true;
            paint.Color       = SKColor.Parse(tpe.HtmlColorCode);
            if (tpe.FillOrStroke == "fill")
            {
                paint.Style = SKPaintStyle.StrokeAndFill;
            }
            else
            {
                paint.Style = SKPaintStyle.Stroke;
            }
            paint.StrokeWidth = tpe.LineWidthDegrees;
            paint.StrokeCap   = SKStrokeCap.Round;
            if (tpe.LinePattern != "solid")
            {
                float[] linesAndGaps = tpe.LinePattern.Split('|').Select(t => float.Parse(t)).ToArray();
                paint.PathEffect = SKPathEffect.CreateDash(linesAndGaps, 0);
                paint.StrokeCap  = SKStrokeCap.Butt;
            }
            if (!string.IsNullOrEmpty(tpe.FileName))
            {
                SKBitmap fillPattern = cachedBitmaps[tpe.FileName];
                //cachedBitmaps.TryAdd(tpe.fileName, fillPattern); //For icons.
                SKShader tiling = SKShader.CreateBitmap(fillPattern, SKShaderTileMode.Repeat, SKShaderTileMode.Repeat); //For fill patterns.
                paint.Shader = tiling;
            }
            return(paint);
        }
        private static SKShader CreateCheckerboardShader(SKColor c1, SKColor c2, int size)
        {
            SKBitmap bm = new SKBitmap(new SKImageInfo(size * 2, size * 2));

            bm.Erase(c1);
            bm.Erase(c2, new SKRectI(0, 0, size, size));
            bm.Erase(c2, new SKRectI(size, size, 2 * size, 2 * size));
            return(SKShader.CreateBitmap(bm, SKShaderTileMode.Repeat, SKShaderTileMode.Repeat));
        }
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            // Get seed value from stepper
            float seed = (float)seedStepper.Value;

            SKRect tileRect = new SKRect(0, 0, TILE_SIZE, TILE_SIZE);

            using (SKBitmap bitmap = new SKBitmap(TILE_SIZE, TILE_SIZE))
            {
                using (SKCanvas bitmapCanvas = new SKCanvas(bitmap))
                {
                    bitmapCanvas.Clear();

                    // Draw tiled turbulence noise on bitmap
                    using (SKPaint paint = new SKPaint())
                    {
                        paint.Shader = SKShader.CreatePerlinNoiseTurbulence(
                            0.02f, 0.02f, 1, seed,
                            new SKPointI(TILE_SIZE, TILE_SIZE));

                        bitmapCanvas.DrawRect(tileRect, paint);
                    }
                }

                // Draw tiled bitmap shader on canvas
                using (SKPaint paint = new SKPaint())
                {
                    paint.Shader = SKShader.CreateBitmap(bitmap,
                                                         SKShaderTileMode.Repeat,
                                                         SKShaderTileMode.Repeat);
                    canvas.DrawRect(info.Rect, paint);
                }

                // Draw rectangle showing tile
                using (SKPaint paint = new SKPaint())
                {
                    paint.Style       = SKPaintStyle.Stroke;
                    paint.Color       = SKColors.Black;
                    paint.StrokeWidth = 2;

                    canvas.DrawRect(tileRect, paint);
                }
            }
        }
Beispiel #9
0
        public GlobalCache(PakIndex index)
        {
            Index      = index;
            VBucksIcon = index.GetPackage("/FortniteGame/Content/UI/Foundation/Shell/Textures/T-Icon-VBucks-L").GetExport <Texture2D>().Image;

            var img = index.GetPackage("/FortniteGame/Content/VisualThreatManager/StormVisuals/Test/SpawnParticles/Streamers/LowResBlurredNoise").GetExport <Texture2D>().Image; // don't dispose objects given by exports

            using (var b = SKBitmap.FromImage(img))
                using (var b2 = new SKBitmap(new SKImageInfo(b.Width * 2, b.Height * 2), SKBitmapAllocFlags.ZeroPixels))
                {
                    using (var c = new SKCanvas(b2))
                        using (var s = SKShader.CreateColorFilter(SKShader.CreateBitmap(b, SKShaderTileMode.Repeat, SKShaderTileMode.Repeat), SKColorFilter.CreateLighting(new SKColor(160, 160, 160), new SKColor(15, 15, 15))))
                        {
                            c.DrawRect(0, 0, b2.Width, b2.Height, new SKPaint {
                                Shader = s
                            });
                        }
                    using (var borderNoiseBig = b2.Resize(new SKImageInfo(b2.Width * 16, b2.Height * 16), SKFilterQuality.Medium))
                        using (var borderNoise = new SKBitmap(b.Width * 16, b.Width * 16))
                        {
                            borderNoiseBig.ExtractSubset(borderNoise, new SKRectI(b2.Width * 4, b2.Width * 4, b2.Width * 12, b2.Width * 12));
                            BaseBorderShader = SKShader.CreateBitmap(borderNoise, SKShaderTileMode.Repeat, SKShaderTileMode.Repeat);
                        }
                }

            NameTypeface             = SKTypeface.FromStream(index.GetFile("/FortniteGame/Content/UI/Foundation/Fonts/BurbankBigCondensed-Black.ufont").AsStream());
            ShortDescriptionTypeface = SKTypeface.FromStream(index.GetFile("/FortniteGame/Content/UI/Foundation/Fonts/NotoSans-Regular.ufont").AsStream());
            PriceTypeface            = SKTypeface.FromStream(index.GetFile("/FortniteGame/Content/UI/Foundation/Fonts/NotoSans-Bold.ufont").AsStream());
            CategoryTypeface         = SKTypeface.FromStream(index.GetFile("/FortniteGame/Content/UI/Foundation/Fonts/NotoSans-Bold.ufont").AsStream());

            ImagePaint = new SKPaint
            {
                IsAntialias   = true,
                FilterQuality = SKFilterQuality.High
            };

            {
                var types = EnumHelper <DrawType> .Values;
                SectionCaches = new SectionCache[types.Length];
                for (int i = 0; i < types.Length; i++)
                {
                    SectionCaches[i] = new SectionCache(types[i], this);
                }
            }

            {
                RarityColors = new ColorPalette[]
                {
                    new ColorPalette(this, default, new SKColor(150, 150, 150), new SKColor(50, 53, 58), new SKColor(212, 212, 212), new SKColor(249, 249, 249)),  // COMMON
Beispiel #10
0
        protected override SKPaint CreatePaint()
        {
            var paint = new SKPaint();

            if (_shader != null)
            {
                _shader.Dispose();
                _shader = null;
            }

            _shader = SKShader.CreateBitmap(_image.Image, SKShaderTileMode.Clamp, SKShaderTileMode.Clamp);

            paint.Shader = _shader;
            return(paint);
        }
Beispiel #11
0
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            using (SKPaint paint = new SKPaint())
            {
                paint.Shader = SKShader.CreateBitmap(bitmap,
                                                     SKShaderTileMode.Mirror,
                                                     SKShaderTileMode.Mirror);
                canvas.DrawRect(info.Rect, paint);
            }
        }
        public HatchBrush(HatchStyle hatchStyle, Color foreColor, Color backColor)
        {
            HatchStyle = hatchStyle;
            SKBitmap bitmap = new SKBitmap(new SKImageInfo(2, 2, SKColorType.Bgra8888));

            bitmap.Erase(backColor.ToSKColor());
            bitmap.SetPixel(0, 0, foreColor.ToSKColor());
            bitmap.SetPixel(1, 1, foreColor.ToSKColor());

            // create the bitmap shader
            var shader = SKShader.CreateBitmap(bitmap, SKShaderTileMode.Repeat, SKShaderTileMode.Repeat);

            // add to the paint
            nativeBrush = new SKPaint()
            {
                Shader = shader, Style = SKPaintStyle.Fill
            };
        }
Beispiel #13
0
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            using (SKPaint paint = new SKPaint())
            {
                // Create bitmap tiling
                paint.Shader = SKShader.CreateBitmap(BrickWallTile,
                                                     SKShaderTileMode.Repeat,
                                                     SKShaderTileMode.Repeat);
                // Draw background
                canvas.DrawRect(info.Rect, paint);
            }
        }
Beispiel #14
0
        public override void Render(SKCanvas canvas)
        {
            // Scale down the render path to avoid computing a value for every pixel
            var width   = (int)(Math.Max(Layer.Rectangle.Width, Layer.Rectangle.Height) / Scale);
            var height  = (int)(Math.Max(Layer.Rectangle.Width, Layer.Rectangle.Height) / Scale);
            var opacity = (float)Math.Round(Settings.Color.Alpha / 255.0, 2, MidpointRounding.AwayFromZero);

            using (var bitmap = new SKBitmap(new SKImageInfo(width, height)))
            {
                bitmap.Erase(new SKColor(0, 0, 0, 0));
                // Only compute pixels inside LEDs, due to scaling there may be some rounding issues but it's neglect-able
                foreach (var artemisLed in Layer.Leds)
                {
                    var xStart = artemisLed.AbsoluteRenderRectangle.Left / Scale;
                    var xEnd   = artemisLed.AbsoluteRenderRectangle.Right / Scale;
                    var yStart = artemisLed.AbsoluteRenderRectangle.Top / Scale;
                    var yEnd   = artemisLed.AbsoluteRenderRectangle.Bottom / Scale;

                    for (var x = xStart; x < xEnd; x++)
                    {
                        for (var y = yStart; y < yEnd; y++)
                        {
                            var v     = _noise.Evaluate(Settings.XScale * x / width, Settings.YScale * y / height, _z);
                            var alpha = (byte)((v + 1) * 127 * opacity);
                            // There's some fun stuff we can do here, like creating hard lines
                            // if (alpha > 128)
                            //     alpha = 255;
                            // else
                            //     alpha = 0;
                            var color = new SKColor(Settings.Color.Red, Settings.Color.Green, Settings.Color.Blue, alpha);
                            bitmap.SetPixel((int)x, (int)y, color);
                        }
                    }
                }

                using (var sh = SKShader.CreateBitmap(bitmap, SKShaderTileMode.Mirror, SKShaderTileMode.Mirror, SKMatrix.MakeScale(Scale, Scale)))
                    using (var paint = new SKPaint {
                        Shader = sh, BlendMode = Settings.BlendMode
                    })
                    {
                        canvas.DrawPath(Layer.LayerShape.RenderPath, paint);
                    }
            }
        }
Beispiel #15
0
        public SKPaint GetFillPaint()
        {
            //新形式
            SKBitmap dstBitmap = new SKBitmap(
                new SKImageInfo(
                    this.Screentone.Info.Width * (int)ScreentoneScale,
                    this.Screentone.Info.Height * (int)ScreentoneScale));

            this.Screentone.ScalePixels(dstBitmap, SKFilterQuality.None);

            SKPaint fillPaint = new SKPaint
            {
                IsAntialias = false,
                Style       = SKPaintStyle.Fill,
                Shader      = SKShader.CreateBitmap(dstBitmap, SKShaderTileMode.Repeat, SKShaderTileMode.Repeat)
            };

            return(fillPaint);
        }
        public MainPage()
        {
            InitializeComponent();

            // Make cat ear path
            catEarPath.MoveTo(0, 0);
            catEarPath.LineTo(0, 75);
            catEarPath.LineTo(100, 75);
            catEarPath.Close();

            // Make cat eye path
            catEyePath.MoveTo(0, 0);
            catEyePath.ArcTo(50, 50, 0, SKPathArcSize.Small, SKPathDirection.Clockwise, 50, 0);
            catEyePath.ArcTo(50, 50, 0, SKPathArcSize.Small, SKPathDirection.Clockwise, 0, 0);
            catEyePath.Close();

            // Make eye pupil path
            catPupilPath.MoveTo(25, -5);
            catPupilPath.ArcTo(6, 6, 0, SKPathArcSize.Small, SKPathDirection.Clockwise, 25, 5);
            catPupilPath.ArcTo(6, 6, 0, SKPathArcSize.Small, SKPathDirection.Clockwise, 25, -5);
            catPupilPath.Close();

            // Make cat tail path
            catTailPath.MoveTo(0, 100);
            catTailPath.CubicTo(50, 200, 0, 250, -50, 200);

            // Create Shader
            Assembly assembly = GetType().GetTypeInfo().Assembly;

            using (Stream stream = assembly.GetManifestResourceStream("SkiaWithXamarin.WoodGrain.png"))
                using (SKManagedStream skStream = new SKManagedStream(stream))
                    using (SKBitmap bitmap = SKBitmap.Decode(skStream))
                        using (SKShader shader = SKShader.CreateBitmap(bitmap, SKShaderTileMode.Mirror, SKShaderTileMode.Mirror))
                        {
                            backgroundFillPaint.Shader = shader;
                        }

            Device.StartTimer(TimeSpan.FromSeconds(1f / 60), () =>
            {
                canvasView.InvalidateSurface();
                return(true);
            });
        }
Beispiel #17
0
        internal PaintWrapper CreateAcrylicPaint(SKPaint paint, IExperimentalAcrylicMaterial material, bool disposePaint = false)
        {
            var paintWrapper = new PaintWrapper(paint, disposePaint);

            paint.IsAntialias = true;

            double opacity = _currentOpacity;

            var tintOpacity =
                material.BackgroundSource == AcrylicBackgroundSource.Digger ?
                material.TintOpacity : 1;

            const double noiseOpcity = 0.0225;

            var tintColor = material.TintColor;
            var tint      = new SKColor(tintColor.R, tintColor.G, tintColor.B, tintColor.A);

            if (s_acrylicNoiseShader == null)
            {
                using (var stream = typeof(DrawingContextImpl).Assembly.GetManifestResourceStream("Avalonia.Skia.Assets.NoiseAsset_256X256_PNG.png"))
                    using (var bitmap = SKBitmap.Decode(stream))
                    {
                        s_acrylicNoiseShader = SKShader.CreateBitmap(bitmap, SKShaderTileMode.Repeat, SKShaderTileMode.Repeat)
                                               .WithColorFilter(CreateAlphaColorFilter(noiseOpcity));
                    }
            }

            using (var backdrop = SKShader.CreateColor(new SKColor(material.MaterialColor.R, material.MaterialColor.G, material.MaterialColor.B, material.MaterialColor.A)))
                using (var tintShader = SKShader.CreateColor(tint))
                    using (var effectiveTint = SKShader.CreateCompose(backdrop, tintShader))
                        using (var compose = SKShader.CreateCompose(effectiveTint, s_acrylicNoiseShader))
                        {
                            paint.Shader = compose;

                            if (material.BackgroundSource == AcrylicBackgroundSource.Digger)
                            {
                                paint.BlendMode = SKBlendMode.Src;
                            }

                            return(paintWrapper);
                        }
        }
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            canvas.DrawBitmap(monkeyBitmap, info.Rect, BitmapStretch.UniformToFill,
                              BitmapAlignment.Center, BitmapAlignment.Start);

            using (SKPaint paint = new SKPaint())
            {
                paint.Shader = SKShader.CreateBitmap(tileBitmap,
                                                     SKShaderTileMode.Repeat,
                                                     SKShaderTileMode.Repeat,
                                                     SKMatrix.MakeRotationDegrees(45));
                canvas.DrawRect(info.Rect, paint);
            }
        }
Beispiel #19
0
        public static SKShader Line(SKColor color)
        {
            using (var bitmap = new SKBitmap(15, 15, true))
            {
                using (var canvas = new SKCanvas(bitmap))
                {
                    canvas.Clear(SKColors.Transparent);
                    using (var paint = new SKPaint())
                    {
                        paint.Color       = color;
                        paint.IsStroke    = true;
                        paint.IsAntialias = true;
                        paint.StrokeWidth = 4;
                        canvas.DrawLine(0, 0, bitmap.Width, 0, paint);
                    }
                }

                // Close enough to 2*PI/8
                return(SKShader.CreateBitmap(bitmap, SKShaderTileMode.Repeat, SKShaderTileMode.Repeat, SKMatrix.MakeRotation(0.8f)));
            }
        }
        protected override void OnDrawSample(SKCanvas canvas, int width, int height)
        {
            // load the image from the embedded resource stream
            using (var stream = new SKManagedStream(SampleMedia.Images.ColorWheel))
                using (var source = SKBitmap.Decode(stream))
                {
                    var matrix = SKMatrix.MakeRotation(30.0f);

                    // create the shader and paint
                    using (var shader = SKShader.CreateBitmap(source, SKShaderTileMode.Repeat, SKShaderTileMode.Repeat, matrix))
                        using (var paint = new SKPaint())
                        {
                            paint.IsAntialias = true;
                            paint.Shader      = shader;

                            // tile the bitmap
                            canvas.Clear(SKColors.White);
                            canvas.DrawPaint(paint);
                        }
                }
        }
Beispiel #21
0
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            using (SKPaint paint = new SKPaint())
            {
                // Create scale transform
                SKMatrix matrix = SKMatrix.MakeScale(0.5f, 0.5f);

                // Create bitmap tiling
                paint.Shader = SKShader.CreateBitmap(bitmap,
                                                     SKShaderTileMode.Mirror,
                                                     SKShaderTileMode.Mirror,
                                                     matrix);
                // Draw background
                canvas.DrawRect(info.Rect, paint);
            }
        }
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info = args.Info;
            SKSurface surface = args.Surface;
            SKCanvas canvas = surface.Canvas;

            canvas.Clear();

            using (SKPaint paint = new SKPaint())
            {
                SKRect rect = new SKRect(info.Width / 7,
                                            info.Height / 7,
                                            6 * info.Width / 7,
                                            6 * info.Height / 7);

                // Get bitmap from other program
                SKBitmap bitmap = AlgorithmicBrickWallPage.BrickWallTile;

                // Create bitmap tiling
                if (!isAligned)
                {
                    paint.Shader = SKShader.CreateBitmap(bitmap,
                                                         SKShaderTileMode.Repeat,
                                                         SKShaderTileMode.Repeat);
                }
                else
                {
                    SKMatrix matrix = SKMatrix.MakeTranslation(rect.Left, rect.Top);

                    paint.Shader = SKShader.CreateBitmap(bitmap,
                                                         SKShaderTileMode.Repeat,
                                                         SKShaderTileMode.Repeat,
                                                         matrix);
                }

                // Draw rectangle
                canvas.DrawRect(rect, paint);
            }
        }
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            // Get tile modes from Pickers
            SKShaderTileMode xTileMode =
                (SKShaderTileMode)(xModePicker.SelectedIndex == -1 ?
                                   0 : xModePicker.SelectedItem);
            SKShaderTileMode yTileMode =
                (SKShaderTileMode)(yModePicker.SelectedIndex == -1 ?
                                   0 : yModePicker.SelectedItem);

            using (SKPaint paint = new SKPaint())
            {
                paint.Shader = SKShader.CreateBitmap(bitmap, xTileMode, yTileMode);
                canvas.DrawRect(info.Rect, paint);
            }
        }
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            float densityMultiplier = args.Info.Height / (float)SkiaCanvas.Height;
            float pixelHeight       = currentHeaderHeight * densityMultiplier;
            float pullPoint         = minHeaderHeight * densityMultiplier;

            canvas.Clear();

            SKPath  path   = new SKPath();
            SKPoint point0 = new SKPoint(0, pixelHeight);
            SKPoint point1 = new SKPoint(args.Info.Width / 2, pullPoint);
            SKPoint point2 = new SKPoint(args.Info.Width, pixelHeight);

            path.MoveTo(0, 0);
            path.LineTo(point0);
            path.ConicTo(point1, point2, (float)weightSlider.Value);
            path.LineTo(args.Info.Width, 0);
            path.LineTo(0, 0);
            path.Close();
            canvas.ClipPath(path, antialias: true);

            using (SKPaint paint = new SKPaint())
            {
                // Create bitmap tiling
                paint.Shader = SKShader.CreateBitmap(resourceBitmap,
                                                     SKShaderTileMode.Repeat,
                                                     SKShaderTileMode.Repeat);
                // Draw background
                canvas.DrawRect(info.Rect, paint);
            }


            //SKRect dest = new SKRect(0, 0, info.Width, info.Height);
            //canvas.DrawBitmap(resourceBitmap, dest, BitmapStretch.AspectFill, BitmapAlignment.Start, BitmapAlignment.Start);
        }
Beispiel #25
0
        public MainPage()
        {
            InitializeComponent();

            //Kedinin kulağı
            catEarPath.MoveTo(0, 0);
            catEarPath.LineTo(0, 75);
            catEarPath.LineTo(100, 75);
            catEarPath.Close();

            //Kedinin Gözü
            catEyePath.MoveTo(0, 0);
            catEyePath.ArcTo(50, 50, 0, SKPathArcSize.Small, SKPathDirection.Clockwise, 50, 0);
            catEyePath.ArcTo(50, 50, 0, SKPathArcSize.Small, SKPathDirection.Clockwise, 0, 0);
            catEyePath.Close();

            // Kedinin Kuyruğu
            catTailPath.MoveTo(0, 100);
            catTailPath.CubicTo(50, 200, 0, 250, -50, 200);

            //Gölge
            Assembly assembly = GetType().GetTypeInfo().Assembly;

            using (Stream stream = assembly.GetManifestResourceStream("CatClockN.WoodGrain.png"))
                using (SKManagedStream skStream = new SKManagedStream(stream))
                    using (SKBitmap bitmap = SKBitmap.Decode(skStream))
                        using (SKShader shader = SKShader.CreateBitmap(bitmap, SKShaderTileMode.Mirror, SKShaderTileMode.Mirror))
                        {
                            backgroundFillPaint.Shader = shader;
                        }

            Device.StartTimer(TimeSpan.FromSeconds(1f / 60), () =>
            {
                canvasView.InvalidateSurface();
                return(true);
            });
        }
Beispiel #26
0
        private void PenTipChanged()
        {
            //ペン先のstrokeカラー設定
            SKColor strokeColor = PaintColors.Transparent;

            switch (strokeColorPicker.SelectedItem as string)
            {
            default:
            case "None":
                strokeColor = PaintColors.Transparent;
                break;

            case "Black":
                strokeColor = PaintColors.Black;
                break;

            case "White":
                strokeColor = PaintColors.White;
                break;

            case "Red":
                strokeColor = PaintColors.Red;
                break;

            case "Yellow":
                strokeColor = PaintColors.Yellow;
                break;

            case "Green":
                strokeColor = PaintColors.Green;
                break;

            case "Blue":
                strokeColor = PaintColors.Blue;
                break;
            }

            SKPaint strokePaint = new SKPaint
            {
                IsAntialias = false,
                Style       = SKPaintStyle.Stroke,
                Color       = strokeColor,
                StrokeWidth = (float)strokeSizeStepper.Value,
                StrokeJoin  = SKStrokeJoin.Round
            };

            inProgressPath.StrokePaint = strokePaint;



            //ペン先のfillカラー設定
            SKColor fillColor = PaintColors.Transparent;

            switch (fillColorPicker.SelectedItem as string)
            {
            default:
            case "None":
                fillColor = PaintColors.Transparent;
                break;

            case "Black":
                fillColor = PaintColors.Black;
                break;

            case "White":
                fillColor = PaintColors.White;
                break;

            case "Red":
                fillColor = PaintColors.Red;
                break;

            case "Yellow":
                fillColor = PaintColors.Yellow;
                break;

            case "Green":
                fillColor = PaintColors.Green;
                break;

            case "Blue":
                fillColor = PaintColors.Blue;
                break;
            }

            SKBitmap bitmap = new SKBitmap();

            //ペン先のパターン設定
            switch (fillPatternPicker.SelectedItem as string)
            {
            default:
            case "Normal":
                bitmap = PaintPatterns.NormalPattern(fillColor);
                break;

            case "Rough3x3":
                bitmap = PaintPatterns.Rough3x3Pattern(fillColor);
                break;

            case "Rough2x2":
                bitmap = PaintPatterns.Rough2x2Pattern(fillColor);
                break;

            case "Beads4x4":
                bitmap = PaintPatterns.Beads4x4Pattern(fillColor);
                break;

            case "StripeX":
                bitmap = PaintPatterns.StripeXPattern(fillColor);
                break;

            case "StripeY":
                bitmap = PaintPatterns.StripeYPattern(fillColor);
                break;

            case "Checkered":
                bitmap = PaintPatterns.CheckeredPattern(fillColor);
                break;

            case "Dense2x2":
                bitmap = PaintPatterns.Dense2x2Pattern(fillColor);
                break;

            case "Dense3x3":
                bitmap = PaintPatterns.Dense3x3Pattern(fillColor);
                break;

            case "LeftHatching":
                bitmap = PaintPatterns.LeftHatching8x8Pattern(fillColor);
                break;

            case "RightHatching":
                bitmap = PaintPatterns.RightHatching8x8Pattern(fillColor);
                break;
            }

            //暫定Pathにpentipを設定
            SKPaint fillPaint = new SKPaint
            {
                IsAntialias = false,
                Style       = SKPaintStyle.Fill,
                Shader      = SKShader.CreateBitmap(bitmap, SKShaderTileMode.Repeat, SKShaderTileMode.Repeat)
            };

            inProgressPath.FillPaint = fillPaint;
        }
Beispiel #27
0
        internal PaintWrapper CreatePaint(IBrush brush, Size targetSize)
        {
            SKPaint paint = new SKPaint();
            var     rv    = new PaintWrapper(paint);

            paint.IsStroke = false;


            double opacity = brush.Opacity * _currentOpacity;

            paint.IsAntialias = true;

            var solid = brush as ISolidColorBrush;

            if (solid != null)
            {
                paint.Color = new SKColor(solid.Color.R, solid.Color.G, solid.Color.B, (byte)(solid.Color.A * opacity));
                return(rv);
            }
            paint.Color = (new SKColor(255, 255, 255, (byte)(255 * opacity)));

            var gradient = brush as IGradientBrush;

            if (gradient != null)
            {
                var tileMode    = gradient.SpreadMethod.ToSKShaderTileMode();
                var stopColors  = gradient.GradientStops.Select(s => s.Color.ToSKColor()).ToArray();
                var stopOffsets = gradient.GradientStops.Select(s => (float)s.Offset).ToArray();

                var linearGradient = brush as ILinearGradientBrush;
                if (linearGradient != null)
                {
                    var start = linearGradient.StartPoint.ToPixels(targetSize).ToSKPoint();
                    var end   = linearGradient.EndPoint.ToPixels(targetSize).ToSKPoint();

                    // would be nice to cache these shaders possibly?
                    using (var shader = SKShader.CreateLinearGradient(start, end, stopColors, stopOffsets, tileMode))
                        paint.Shader = shader;
                }
                else
                {
                    var radialGradient = brush as IRadialGradientBrush;
                    if (radialGradient != null)
                    {
                        var center = radialGradient.Center.ToPixels(targetSize).ToSKPoint();
                        var radius = (float)radialGradient.Radius;

                        // TODO: There is no SetAlpha in SkiaSharp
                        //paint.setAlpha(128);

                        // would be nice to cache these shaders possibly?
                        using (var shader = SKShader.CreateRadialGradient(center, radius, stopColors, stopOffsets, tileMode))
                            paint.Shader = shader;
                    }
                }

                return(rv);
            }

            var tileBrush      = brush as ITileBrush;
            var visualBrush    = brush as IVisualBrush;
            var tileBrushImage = default(BitmapImpl);

            if (visualBrush != null)
            {
                if (_visualBrushRenderer != null)
                {
                    var intermediateSize = _visualBrushRenderer.GetRenderTargetSize(visualBrush);

                    if (intermediateSize.Width >= 1 && intermediateSize.Height >= 1)
                    {
                        var intermediate = new BitmapImpl((int)intermediateSize.Width, (int)intermediateSize.Height);

                        using (var ctx = intermediate.CreateDrawingContext(_visualBrushRenderer))
                        {
                            ctx.Clear(Colors.Transparent);
                            _visualBrushRenderer.RenderVisualBrush(ctx, visualBrush);
                        }

                        rv.AddDisposable(tileBrushImage);
                        tileBrushImage = intermediate;
                    }
                }
                else
                {
                    throw new NotSupportedException("No IVisualBrushRenderer was supplied to DrawingContextImpl.");
                }
            }
            else
            {
                tileBrushImage = (BitmapImpl)((tileBrush as IImageBrush)?.Source?.PlatformImpl);
            }

            if (tileBrush != null && tileBrushImage != null)
            {
                var calc   = new TileBrushCalculator(tileBrush, new Size(tileBrushImage.PixelWidth, tileBrushImage.PixelHeight), targetSize);
                var bitmap = new BitmapImpl((int)calc.IntermediateSize.Width, (int)calc.IntermediateSize.Height);
                rv.AddDisposable(bitmap);
                using (var context = bitmap.CreateDrawingContext(null))
                {
                    var rect = new Rect(0, 0, tileBrushImage.PixelWidth, tileBrushImage.PixelHeight);

                    context.Clear(Colors.Transparent);
                    context.PushClip(calc.IntermediateClip);
                    context.Transform = calc.IntermediateTransform;
                    context.DrawImage(tileBrushImage, 1, rect, rect);
                    context.PopClip();
                }

                SKMatrix         translation = SKMatrix.MakeTranslation(-(float)calc.DestinationRect.X, -(float)calc.DestinationRect.Y);
                SKShaderTileMode tileX       =
                    tileBrush.TileMode == TileMode.None
                        ? SKShaderTileMode.Clamp
                        : tileBrush.TileMode == TileMode.FlipX || tileBrush.TileMode == TileMode.FlipXY
                            ? SKShaderTileMode.Mirror
                            : SKShaderTileMode.Repeat;

                SKShaderTileMode tileY =
                    tileBrush.TileMode == TileMode.None
                        ? SKShaderTileMode.Clamp
                        : tileBrush.TileMode == TileMode.FlipY || tileBrush.TileMode == TileMode.FlipXY
                            ? SKShaderTileMode.Mirror
                            : SKShaderTileMode.Repeat;
                using (var shader = SKShader.CreateBitmap(bitmap.Bitmap, tileX, tileY, translation))
                    paint.Shader = shader;
            }

            return(rv);
        }
        internal PaintWrapper CreatePaint(IBrush brush, Size targetSize)
        {
            SKPaint paint = new SKPaint();
            var     rv    = new PaintWrapper(paint);

            paint.IsStroke = false;

            // TODO: SkiaSharp does not contain alpha yet!
            double opacity = brush.Opacity * _currentOpacity;

            //paint.SetAlpha(paint.GetAlpha() * opacity);
            paint.IsAntialias = true;

            SKColor color = new SKColor(255, 255, 255, 255);

            var solid = brush as ISolidColorBrush;

            if (solid != null)
            {
                color = solid.Color.ToSKColor();
            }

            paint.Color = (new SKColor(color.Red, color.Green, color.Blue, (byte)(color.Alpha * opacity)));

            if (solid != null)
            {
                return(rv);
            }

            var gradient = brush as GradientBrush;

            if (gradient != null)
            {
                var tileMode    = gradient.SpreadMethod.ToSKShaderTileMode();
                var stopColors  = gradient.GradientStops.Select(s => s.Color.ToSKColor()).ToArray();
                var stopOffsets = gradient.GradientStops.Select(s => (float)s.Offset).ToArray();

                var linearGradient = brush as LinearGradientBrush;
                if (linearGradient != null)
                {
                    var start = linearGradient.StartPoint.ToPixels(targetSize).ToSKPoint();
                    var end   = linearGradient.EndPoint.ToPixels(targetSize).ToSKPoint();

                    // would be nice to cache these shaders possibly?
                    using (var shader = SKShader.CreateLinearGradient(start, end, stopColors, stopOffsets, tileMode))
                        paint.Shader = shader;
                }
                else
                {
                    var radialGradient = brush as RadialGradientBrush;
                    if (radialGradient != null)
                    {
                        var center = radialGradient.Center.ToPixels(targetSize).ToSKPoint();
                        var radius = (float)radialGradient.Radius;

                        // TODO: There is no SetAlpha in SkiaSharp
                        //paint.setAlpha(128);

                        // would be nice to cache these shaders possibly?
                        using (var shader = SKShader.CreateRadialGradient(center, radius, stopColors, stopOffsets, tileMode))
                            paint.Shader = shader;
                    }
                }

                return(rv);
            }

            var tileBrush = brush as TileBrush;

            if (tileBrush != null)
            {
                var helper = new TileBrushImplHelper(tileBrush, targetSize);
                var bitmap = new BitmapImpl((int)helper.IntermediateSize.Width, (int)helper.IntermediateSize.Height);
                rv.AddDisposable(bitmap);
                using (var ctx = bitmap.CreateDrawingContext())
                    helper.DrawIntermediate(ctx);
                SKMatrix         translation = SKMatrix.MakeTranslation(-(float)helper.DestinationRect.X, -(float)helper.DestinationRect.Y);
                SKShaderTileMode tileX       =
                    tileBrush.TileMode == TileMode.None
                        ? SKShaderTileMode.Clamp
                        : tileBrush.TileMode == TileMode.FlipX || tileBrush.TileMode == TileMode.FlipXY
                            ? SKShaderTileMode.Mirror
                            : SKShaderTileMode.Repeat;

                SKShaderTileMode tileY =
                    tileBrush.TileMode == TileMode.None
                        ? SKShaderTileMode.Clamp
                        : tileBrush.TileMode == TileMode.FlipY || tileBrush.TileMode == TileMode.FlipXY
                            ? SKShaderTileMode.Mirror
                            : SKShaderTileMode.Repeat;
                using (var shader = SKShader.CreateBitmap(bitmap.Bitmap, tileX, tileY, translation))
                    paint.Shader = shader;
            }

            return(rv);
        }
Beispiel #29
0
        //-----------------------------------------------------------------------------
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs e)
        {
            if (bmpSrc == null)
            {
                return;
            }

            // identify left, right halves and a 10px wide swath of the middle of the source bitmap
            SKRect rectSrcLeft  = new SKRect(0, 0, bmpSrc.Width / 2, bmpSrc.Height);
            SKRect rectSrcRight = new SKRect(bmpSrc.Width / 2, 0, bmpSrc.Width, bmpSrc.Height);
            SKRect rectSrcMid   = new SKRect(bmpSrc.Width / 2 - 5, 0, bmpSrc.Width / 2 + 5, bmpSrc.Height);

            // create a new bitmap containing a 10 pixel wide swatch from middle of bmpSrc
            SKBitmap bmpSrcMid = new SKBitmap(10, bmpSrc.Height);

            using (SKCanvas tempCanvas = new SKCanvas(bmpSrcMid))
            {
                SKRect rectDest = new SKRect(0, 0, rectSrcMid.Width, rectSrcRight.Height);
                tempCanvas.DrawBitmap(bmpSrc, rectSrcMid, rectDest);
            }

            var canvas = e.Surface.Canvas;

            // scale canvas so that bmpSrc matches in height
            canvas.Save();
            float hDest = canvas.DeviceClipBounds.Height;
            float scale = hDest / (float)bmpSrc.Height;

            canvas.Scale(scale);

            // determine dest rect for middle section
            float  rightDest   = (float)textBounds.Width / scale; // rightmost point of whole target area
            SKRect rectDestMid = new SKRect(rectSrcLeft.Width, 0, rightDest - rectSrcRight.Width, rectSrcRight.Height);

            // left part of tab
            canvas.DrawBitmap(bmpSrc, rectSrcLeft, rectSrcLeft);

            // right part of tab
            {
                SKRect rectDest = new SKRect(rectDestMid.Right, 0, rightDest, rectSrcRight.Height);
                canvas.DrawBitmap(bmpSrc, rectSrcRight, rectDest);
            }

            // mid part of tab
            using (SKPaint paint = new SKPaint())
            {
                paint.Shader = SKShader.CreateBitmap(bmpSrcMid,
                                                     SKShaderTileMode.Repeat,
                                                     SKShaderTileMode.Repeat);
                // Draw background
                canvas.DrawRect(rectDestMid, paint);
            }

            canvas.Restore(); // back to orig scale

            using (SKPaint paint = new SKPaint {
                Color = SKColors.Black
            })
            {
                paint.TextSize = paint.TextSize * (float)DeviceDisplay.MainDisplayInfo.Density;
                float leftText = DiuToPixels(20); // matches padding in ListPage.xaml
                float topText  = canvas.DeviceClipBounds.Height / 2 + textCoreHeight / 2;
                Debug.WriteLine("SI: text LT " + leftText + ", " + topText);
                canvas.DrawText(Label, new SKPoint(leftText, topText), paint);
            }
        }
Beispiel #30
0
        //-----------------------------------------------------------------------------
        private void OnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            if (bmpSrc == null || Label == null)
            {
                return;
            }

            var canvas = e.Surface.Canvas;

            // Resize bitmap to match height of "this"
            Log.L("SI: canvas wh " + canvas.DeviceClipBounds.Width + ", " + canvas.DeviceClipBounds.Height);
            if (bmpSrc.Height != canvas.DeviceClipBounds.Height) // resize
            {
                float hDest = canvas.DeviceClipBounds.Height;    // actual pixels
                float scale = hDest / (float)bmpSrc.Height;
                float wDest = bmpSrc.Width * scale;
                bmpSrc = bmpSrc.Resize(new SKSizeI((int)wDest, (int)hDest), SKFilterQuality.High);
            }

            // identify left, right halves and a 10px wide swath of the middle of the source bitmap
            SKRect rectSrcLeft  = new SKRect(0, 0, bmpSrc.Width / 2, bmpSrc.Height);
            SKRect rectSrcRight = new SKRect(bmpSrc.Width / 2, 0, bmpSrc.Width, bmpSrc.Height);
            SKRect rectSrcMid   = new SKRect(bmpSrc.Width / 2 - 5, 0, bmpSrc.Width / 2 + 5, bmpSrc.Height);

            // create a new bitmap containing a 10 pixel wide swatch from middle of bmpSrc
            SKBitmap bmpSrcMid = new SKBitmap(10, bmpSrc.Height);

            using (SKCanvas tempCanvas = new SKCanvas(bmpSrcMid))
            {
                SKRect rectDest = new SKRect(0, 0, rectSrcMid.Width, rectSrcRight.Height);
                tempCanvas.DrawBitmap(bmpSrc, rectSrcMid, rectDest);
            }

            using (SKPaint paint = new SKPaint())
            {
//        paint.Color = new SKColor (0, 255, 255);
//        canvas.DrawRect (0, 0, canvas.DeviceClipBounds.Width, canvas.DeviceClipBounds.Height, paint);

                paint.IsAntialias = false;

                // determine dest rect for middle section
                float  rightDest   = canvas.DeviceClipBounds.Width;
                SKRect rectDestMid = new SKRect(rectSrcLeft.Width, 0, rightDest - rectSrcRight.Width, rectSrcRight.Height);

                // left part of tab
                canvas.DrawBitmap(bmpSrc, rectSrcLeft, rectSrcLeft, paint);
                Log.L("SI: hSrc " + bmpSrc.Height);

                // right part of tab
                {
                    SKRect rectDest = new SKRect(rectDestMid.Right, 0, rightDest, rectSrcRight.Height);
                    canvas.DrawBitmap(bmpSrc, rectSrcRight, rectDest, paint);
                }

                // mid part of tab
                paint.Shader = SKShader.CreateBitmap(bmpSrcMid,
                                                     SKShaderTileMode.Repeat,
                                                     SKShaderTileMode.Repeat);
                canvas.DrawRect(rectDestMid, paint);
            }

            using (SKPaint paint = new SKPaint {
                Color = SKColors.Black
            })
            {
                paint.TextSize = (paint.TextSize + textSizeAdjustment) * getScreenScaleFactor();
                float leftText   = padding * getScreenScaleFactor();
                float bottomText = canvas.DeviceClipBounds.Height / 2 + textCoreHeight / 2;
                canvas.DrawText(Label, new SKPoint(leftText, bottomText), paint);
            }
        }