Пример #1
6
		public void Erase (SKColor color, SKRectI rect)
		{
			SkiaApi.sk_bitmap_erase_rect (Handle, color, ref rect);
		}
Пример #2
1
        public static void RenderRaster(SKCanvas canvas, SKBitmap bitmap, SKRect rect, float opacity = 1f)
        {
            // Better for quality. Helps to compare to WPF
            var color = new SKColor(255, 255, 255, (byte)(255 * opacity));
            var paint = new SKPaint { Color = color, FilterQuality = SKFilterQuality.High };
            canvas.DrawBitmap(bitmap, rect, paint);

            // Better for performance:
            canvas.DrawBitmap(bitmap, rect);
        }
        public SkiaCanvasState(SkiaCanvasState prototype) : base(prototype)
        {
            _strokeColor = prototype._strokeColor;
            _fillColor   = prototype._fillColor;
            _fontColor   = prototype._fontColor;

            _fontPaint       = prototype.FontPaint.CreateCopy();
            _fillPaint       = prototype.FillPaint.CreateCopy();
            _strokePaint     = prototype.StrokePaint.CreateCopy();
            _fontName        = prototype._fontName;
            _fontSize        = prototype._fontSize;
            Alpha            = prototype.Alpha;
            _scaleX          = prototype._scaleX;
            _scaleY          = prototype._scaleY;
            _typefaceInvalid = false;

            _isBlurred  = prototype._isBlurred;
            _blurRadius = prototype._blurRadius;

            _shadowed = prototype._shadowed;
            //_shadowFilter = prototype._shadowFilter;  // There is no reason the copy really needs to know about this.
            _shadowColor = prototype._shadowColor;
            _shadowX     = prototype._shadowX;
            _shadowY     = prototype._shadowY;
            _shadowBlur  = prototype._shadowBlur;
        }
Пример #4
0
 public SKColorTable(SKColor[] colors, int count)
     : this(SkiaApi.sk_colortable_new (colors, count), true)
 {
     if (Handle == IntPtr.Zero) {
         throw new InvalidOperationException ("Unable to create a new SKColorTable instance.");
     }
 }
Пример #5
0
		public static SKShader CreateLinearGradient (SKPoint start, SKPoint end, SKColor [] colors, float [] colorPos, SKShaderTileMode mode, SKMatrix localMatrix)
		{
			if (colors == null)
				throw new ArgumentNullException (nameof (colors));
			if (colorPos == null) {
				return GetObject<SKShader> (SkiaApi.sk_shader_new_linear_gradient (new SKPoint [] { start, end }, colors, IntPtr.Zero, colors.Length, mode, ref localMatrix));
			} else {
				if (colors.Length != colorPos.Length)
					throw new ArgumentException ("The number of colors must match the number of color positions.");
				return GetObject<SKShader> (SkiaApi.sk_shader_new_linear_gradient (new SKPoint [] { start, end }, colors, colorPos, colors.Length, mode, ref localMatrix));
			}
		}
Пример #6
0
        private void Draw(int[] data, int width, int height, int iterations, SKColor color)
        {
            var pixels = new SKColor[width * height];

            for (int i = 0; i < width * height; i++)
            {
                if (data[i] == iterations)
                {
                    pixels[i] = color;
                }
                else
                {
                    pixels[i] = new SkiaSharp.SKColor((UInt32)(4000000000 / ((data[i] < 1) ? 1 : data[i])));
                }
            }

            bitmap        = new SKBitmap(width, height);
            bitmap.Pixels = pixels;
        }
Пример #7
0
        public static bool TryParse(string hexString, out SKColor color)
        {
            if (string.IsNullOrWhiteSpace(hexString))
            {
                // error
                color = SKColor.Empty;
                return(false);
            }

            // clean up string
            hexString = hexString.Trim().ToUpperInvariant();
            if (hexString [0] == '#')
            {
                hexString = hexString.Substring(1);
            }

            var len = hexString.Length;

            if (len == 3 || len == 4)
            {
                byte a, r, g, b;
                // parse [A]
                if (len == 4)
                {
                    if (!byte.TryParse(string.Concat(hexString [len - 4], hexString [len - 4]), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out a))
                    {
                        // error
                        color = SKColor.Empty;
                        return(false);
                    }
                }
                else
                {
                    a = 255;
                }

                // parse RGB
                if (!byte.TryParse(string.Concat(hexString [len - 3], hexString [len - 3]), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out r) ||
                    !byte.TryParse(string.Concat(hexString [len - 2], hexString [len - 2]), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out g) ||
                    !byte.TryParse(string.Concat(hexString [len - 1], hexString [len - 1]), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out b))
                {
                    // error
                    color = SKColor.Empty;
                    return(false);
                }

                // success
                color = new SKColor(r, g, b, a);
                return(true);
            }

            if (len == 6 || len == 8)
            {
                // parse [AA]RRGGBB
                uint number;
                if (!uint.TryParse(hexString, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out number))
                {
                    // error
                    color = SKColor.Empty;
                    return(false);
                }

                // success
                color = (SKColor)number;

                // alpha was not provided, so use 255
                if (len == 6)
                {
                    color = color.WithAlpha(255);
                }
                return(true);
            }

            // error
            color = SKColor.Empty;
            return(false);
        }
Пример #8
0
		public static SKShader CreateTwoPointConicalGradient (SKPoint start, float startRadius, SKPoint end, float endRadius, SKColor [] colors, float [] colorPos, SKShaderTileMode mode, SKMatrix localMatrix)
		{
			if (colors == null)
				throw new ArgumentNullException (nameof (colors));
			if (colorPos == null) {
				return GetObject<SKShader> (SkiaApi.sk_shader_new_two_point_conical_gradient (ref start, startRadius, ref end, endRadius, colors, IntPtr.Zero, colors.Length, mode, ref localMatrix));
			} else {
				if (colors.Length != colorPos.Length)
					throw new ArgumentException ("The number of colors must match the number of color positions.");
				return GetObject<SKShader> (SkiaApi.sk_shader_new_two_point_conical_gradient (ref start, startRadius, ref end, endRadius, colors, colorPos, colors.Length, mode, ref localMatrix));
			}
		}
Пример #9
0
 public void Clear(SKColor color)
 {
     DrawColor(color, SKXferMode.Src);
 }
Пример #10
0
		public void DrawColor (SKColor color, SKXferMode mode)
		{
			DrawColor (color, (SKBlendMode)(int)mode);
		}
Пример #11
0
        public static SKColor SKColor(this Color color)
        {
            var skcol = new SkiaSharp.SKColor((uint)color.ToArgb());

            return(skcol);
        }
Пример #12
0
 public void Erase(SKColor color)
 {
     SkiaApi.sk_bitmap_erase(Handle, color);
 }
Пример #13
0
 public void DrawColor(SKColor color, SKXferMode mode = SKXferMode.Src)
 {
     SkiaApi.sk_canvas_draw_color(Handle, color, mode);
 }
Пример #14
0
 public void DrawPoint(float x, float y, SKColor color)
 {
     SkiaApi.sk_canvas_draw_point_color (Handle, x, y, color);
 }
Пример #15
0
		public static SKImageFilter CreatePointLitSpecular(SKPoint3 location, SKColor lightColor, float surfaceScale, float ks, float shininess, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null)
		{
			return GetObject<SKImageFilter>(SkiaApi.sk_imagefilter_new_point_lit_specular(ref location, lightColor, surfaceScale, ks, shininess, input == null ? IntPtr.Zero : input.Handle, cropRect == null ? IntPtr.Zero : cropRect.Handle));
		}
Пример #16
0
		public void Erase (SKColor color)
		{
			SkiaApi.sk_bitmap_erase (Handle, color);
		}
Пример #17
0
        // PreMultiply

        public static SKPMColor PreMultiply(SKColor color) =>
        SkiaApi.sk_color_premultiply((uint)color);
Пример #18
0
 public static SKPMColor PreMultiply(SKColor color)
 {
     return(SkiaApi.sk_color_premultiply(color));
 }
Пример #19
0
        // CreateColor

        public static SKShader CreateColor(SKColor color) =>
        GetObject <SKShader> (SkiaApi.sk_shader_new_color((uint)color));
Пример #20
0
 public bool Erase(SKColor color, SKRectI subset)
 {
     return(SkiaApi.sk_pixmap_erase_color(Handle, color, ref subset));
 }
Пример #21
0
 public bool Erase(SKColor color)
 {
     return(Erase(color, Rect));
 }
Пример #22
0
 public void Clear(SKColor color)
 {
     DrawColor(color, SKBlendMode.Src);
 }
Пример #23
0
 public void DrawPoint(SKPoint p, SKColor color)
 {
     DrawPoint(p.X, p.Y, color);
 }
Пример #24
0
		public static SKImageFilter CreateDistantLitDiffuse(SKPoint3 direction, SKColor lightColor, float surfaceScale, float kd, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null)
		{
			return GetObject<SKImageFilter>(SkiaApi.sk_imagefilter_new_distant_lit_diffuse(ref direction, lightColor, surfaceScale, kd, input == null ? IntPtr.Zero : input.Handle, cropRect == null ? IntPtr.Zero : cropRect.Handle));
		}
Пример #25
0
        // DrawColor

        public void DrawColor(SKColor color, SKBlendMode mode = SKBlendMode.Src)
        {
            SkiaApi.sk_canvas_draw_color(Handle, (uint)color, mode);
        }
Пример #26
0
 public void Clear(SKColor color)
 {
     DrawColor (color, SKXferMode.Src);
 }
Пример #27
0
 public static SKColorFilter CreateBlendMode(SKColor c, SKBlendMode mode)
 {
     return(GetObject <SKColorFilter>(SkiaApi.sk_colorfilter_new_mode((uint)c, mode)));
 }
Пример #28
0
 public PaintState(SKPaint paint, SKColor color, SKShader shader)
 {
     _paint = paint;
     _color = color;
     _shader = shader;
 }
Пример #29
0
 public static SKImageFilter CreateDistantLitSpecular(SKPoint3 direction, SKColor lightColor, float surfaceScale, float ks, float shininess, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null)
 {
     return(GetObject <SKImageFilter>(SkiaApi.sk_imagefilter_new_distant_lit_specular(ref direction, lightColor, surfaceScale, ks, shininess, input == null ? IntPtr.Zero : input.Handle, cropRect == null ? IntPtr.Zero : cropRect.Handle)));
 }
Пример #30
0
		public extern static sk_shader_t sk_shader_new_color(SKColor color);
Пример #31
0
 public static SKImageFilter CreateDropShadow(float dx, float dy, float sigmaX, float sigmaY, SKColor color, SKDropShadowImageFilterShadowMode shadowMode, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null)
 {
     return(GetObject <SKImageFilter>(SkiaApi.sk_imagefilter_new_drop_shadow(dx, dy, sigmaX, sigmaY, color, shadowMode, input == null ? IntPtr.Zero : input.Handle, cropRect == null ? IntPtr.Zero : cropRect.Handle)));
 }
Пример #32
0
 public void Erase(SKColor color, SKRectI rect)
 {
     SkiaApi.sk_bitmap_erase_rect(Handle, color, ref rect);
 }
Пример #33
0
 public static SKImageFilter CreatePointLitDiffuse(SKPoint3 location, SKColor lightColor, float surfaceScale, float kd, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null)
 {
     return(GetObject <SKImageFilter>(SkiaApi.sk_imagefilter_new_point_lit_diffuse(ref location, lightColor, surfaceScale, kd, input == null ? IntPtr.Zero : input.Handle, cropRect == null ? IntPtr.Zero : cropRect.Handle)));
 }
Пример #34
0
 public static void RenderTexture(SKCanvas canvas, SKBitmap bitmap, SKRect rect, float opacity = 1f)
 {
     var color = new SKColor(255, 255, 255, (byte) (255*opacity));
     var paint = new SKPaint {Color = color, FilterQuality = SKFilterQuality.High};
     canvas.DrawBitmap(bitmap, rect, paint);
 }
Пример #35
0
 public static SKImageFilter CreateSpotLitDiffuse(SKPoint3 location, SKPoint3 target, float specularExponent, float cutoffAngle, SKColor lightColor, float surfaceScale, float kd, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null)
 {
     return(GetObject <SKImageFilter>(SkiaApi.sk_imagefilter_new_spot_lit_diffuse(ref location, ref target, specularExponent, cutoffAngle, lightColor, surfaceScale, kd, input == null ? IntPtr.Zero : input.Handle, cropRect == null ? IntPtr.Zero : cropRect.Handle)));
 }
Пример #36
0
		public void Clear (SKColor color)
		{
			DrawColor (color, SKBlendMode.Src);
		}
Пример #37
0
        private void ReadPaints(Dictionary <string, string> style, ref SKPaint strokePaint, ref SKPaint fillPaint)
        {
            // stroke
            var stroke = GetString(style, "stroke").Trim();

            if (stroke.Equals("none", StringComparison.OrdinalIgnoreCase))
            {
                strokePaint = null;
            }
            else
            {
                if (string.IsNullOrEmpty(stroke))
                {
                    // no change
                }
                else
                {
                    if (strokePaint == null)
                    {
                        strokePaint = CreatePaint(true);
                    }

                    SKColor color;
                    if (SKColor.TryParse(stroke, out color))
                    {
                        // preserve alpha
                        if (color.Alpha == 255)
                        {
                            strokePaint.Color = color.WithAlpha(strokePaint.Color.Alpha);
                        }
                        else
                        {
                            strokePaint.Color = color;
                        }
                    }
                }

                // stroke attributes
                var strokeWidth = GetString(style, "stroke-width");
                if (!string.IsNullOrWhiteSpace(strokeWidth))
                {
                    if (strokePaint == null)
                    {
                        strokePaint = CreatePaint(true);
                    }
                    strokePaint.StrokeWidth = ReadNumber(strokeWidth);
                }

                var strokeOpacity = GetString(style, "stroke-opacity");
                if (!string.IsNullOrWhiteSpace(strokeOpacity))
                {
                    if (strokePaint == null)
                    {
                        strokePaint = CreatePaint(true);
                    }
                    strokePaint.Color = strokePaint.Color.WithAlpha((byte)(ReadNumber(strokeOpacity) * 255));
                }
            }

            // fill
            var fill = GetString(style, "fill").Trim();

            if (fill.Equals("none", StringComparison.OrdinalIgnoreCase))
            {
                fillPaint = null;
            }
            else
            {
                if (string.IsNullOrEmpty(fill))
                {
                    // no change
                }
                else
                {
                    if (fillPaint == null)
                    {
                        fillPaint = CreatePaint();
                    }

                    SKColor color;
                    if (SKColor.TryParse(fill, out color))
                    {
                        // preserve alpha
                        if (color.Alpha == 255)
                        {
                            fillPaint.Color = color.WithAlpha(fillPaint.Color.Alpha);
                        }
                        else
                        {
                            fillPaint.Color = color;
                        }
                    }
                    else
                    {
                        var read = false;
                        var urlM = fillUrlRe.Match(fill);
                        if (urlM.Success)
                        {
                            var id = urlM.Groups[1].Value.Trim();

                            XElement defE;
                            if (defs.TryGetValue(id, out defE))
                            {
                                var gradientShader = ReadGradient(defE);
                                if (gradientShader != null)
                                {
                                    // TODO: multiple shaders

                                    fillPaint.Shader = gradientShader;
                                    read             = true;
                                }
                                // else try another type (eg: image)
                            }
                            else
                            {
                                LogOrThrow($"Invalid fill url reference: {id}");
                            }
                        }

                        if (!read)
                        {
                            LogOrThrow($"Unsupported fill: {fill}");
                        }
                    }
                }

                // fill attributes
                var fillOpacity = GetString(style, "fill-opacity");
                if (!string.IsNullOrWhiteSpace(fillOpacity))
                {
                    if (fillPaint == null)
                    {
                        fillPaint = CreatePaint();
                    }

                    fillPaint.Color = fillPaint.Color.WithAlpha((byte)(ReadNumber(fillOpacity) * 255));
                }
            }
        }
Пример #38
0
		public static SKShader CreateSweepGradient (SKPoint center, SKColor [] colors, float [] colorPos, SKMatrix localMatrix)
		{
			if (colors == null)
				throw new ArgumentNullException (nameof (colors));
			if (colorPos == null) {
				return GetObject<SKShader> (SkiaApi.sk_shader_new_sweep_gradient (ref center, colors, IntPtr.Zero, colors.Length, ref localMatrix));
			} else {
				if (colors.Length != colorPos.Length)
					throw new ArgumentException ("The number of colors must match the number of color positions.");
				return GetObject<SKShader> (SkiaApi.sk_shader_new_sweep_gradient (ref center, colors, colorPos, colors.Length, ref localMatrix));
			}
		}
 public static SKShader CreateColor(SKColor color)
 {
     return(GetObject <SKShader> (SkiaApi.sk_shader_new_color(color)));
 }
Пример #40
0
		public static SKShader CreateColor (SKColor color)
		{
			return GetObject<SKShader> (SkiaApi.sk_shader_new_color (color));
		}
Пример #41
0
 public void Erase(SKColor color, SKRectI rect)
 {
     SkiaApi.sk_bitmap_erase_rect(Handle, (uint)color, &rect);
 }
Пример #42
0
		public static SKShader CreateRadialGradient (SKPoint center, float radius, SKColor [] colors, float [] colorPos, SKShaderTileMode mode)
		{
			if (colors == null)
				throw new ArgumentNullException (nameof (colors));
			if (colorPos == null) {
				return GetObject<SKShader> (SkiaApi.sk_shader_new_radial_gradient (ref center, radius, colors, IntPtr.Zero, colors.Length, mode, IntPtr.Zero));
			} else {
				if (colors.Length != colorPos.Length)
					throw new ArgumentException ("The number of colors must match the number of color positions.");
				return GetObject<SKShader> (SkiaApi.sk_shader_new_radial_gradient (ref center, radius, colors, colorPos, colors.Length, mode, IntPtr.Zero));
			}
		}
Пример #43
0
 public void SetPixel(int x, int y, SKColor color)
 {
     SkiaApi.sk_bitmap_set_pixel_color(Handle, x, y, (uint)color);
 }
Пример #44
0
        } // End Function LoadImage

        private void DrawImage()
        {
            int bitness = System.IntPtr.Size * 8;

            System.Console.WriteLine(bitness);


            // https://developer.xamarin.com/guides/cross-platform/drawing/introduction/
            // https://developer.xamarin.com/api/type/SkiaSharp.SKSurface/
            // https://forums.xamarin.com/discussion/77883/skiasharp-graphics-basics


            // Make sure the Microsoft Visual C++ 2015 Redistributable is installed if this error occurs:
            // Unable to load DLL 'libSkiaSharp.dll': The specified module could not be found.
            using (SKSurface surface = SKSurface.Create(width: 640, height: 480, colorType: SKColorType.Bgra8888, alphaType: SKAlphaType.Premul))
            {
                SKCanvas canvas = surface.Canvas;

                canvas.Clear(SKColors.Transparent);


                using (SKPaint paint = new SKPaint())
                {
                    // paint.ImageFilter = SKImageFilter.CreateBlur(5, 5); // Dispose !
                    paint.IsAntialias = true;
                    // paint.Color = new SKColor(0xff, 0x00, 0xff);
                    paint.Color = new SKColor(0x2c, 0x3e, 0x50);

                    paint.StrokeCap = SKStrokeCap.Round;

                    paint.Typeface = SkiaSharp.SKTypeface.FromFamilyName("Impact", SKTypefaceStyle.Bold);
                    paint.TextSize = 12;

                    canvas.DrawText("foobar", 10, 10, paint);
                    // SkiaSharp.SKRect rect = new SkiaSharp.SKRect();
                    SkiaSharp.SKRect rect = MeasureText("foobar", "Impact", 12, SKTypefaceStyle.Bold);
                    // paint.MeasureText("foobar", ref rect);
                    System.Console.WriteLine(rect);

                    SKRect textOverlayRectangle = new SKRect();
                    textOverlayRectangle.Left = 9;                // x
                    textOverlayRectangle.Top  = 10 - rect.Height; // y

                    textOverlayRectangle.Right  = textOverlayRectangle.Left + rect.Width;
                    textOverlayRectangle.Bottom = textOverlayRectangle.Top + rect.Height;

                    // canvas.DrawRect(textOverlayRectangle, paint);



                    // https://chromium.googlesource.com/external/skia/+/master/experimental/SkiaExamples/HelloSkiaExample.cpp
                    SkiaSharp.SKPoint[] linearPoints = new SkiaSharp.SKPoint[] {
                        new SkiaSharp.SKPoint(0, 0),
                        new SkiaSharp.SKPoint(300, 300)
                    };
                    SkiaSharp.SKColor[] linearColors = new SkiaSharp.SKColor[] { SkiaSharp.SKColors.Green, SkiaSharp.SKColors.Black };


                    // canvas.Restore();
                    // canvas.Translate(100, 200);
                    // canvas.RotateDegrees(45);

                    // SKShader shader = SkiaSharp.SKShader.CreateLinearGradient(linearPoints[0], linearPoints[1], linearColors, new float[] { 1.0f, 2000.0f }, SKShaderTileMode.Repeat);
                    // paint.Shader = shader;

                    SkiaSharp.SKBitmap shaderPattern = LoadImage(MapProjectPath(@"~mytile.png"));
                    SKShader           hatchShader   = SkiaSharp.SKShader.CreateBitmap(shaderPattern, SKShaderTileMode.Mirror, SKShaderTileMode.Repeat);
                    paint.Shader = hatchShader;



                    // create the Xamagon path
                    using (SKPath path = new SKPath())
                    {
                        path.MoveTo(71.4311121f, 56f);
                        path.CubicTo(68.6763107f, 56.0058575f, 65.9796704f, 57.5737917f, 64.5928855f, 59.965729f);
                        path.LineTo(43.0238921f, 97.5342563f);
                        path.CubicTo(41.6587026f, 99.9325978f, 41.6587026f, 103.067402f, 43.0238921f, 105.465744f);
                        path.LineTo(64.5928855f, 143.034271f);
                        path.CubicTo(65.9798162f, 145.426228f, 68.6763107f, 146.994582f, 71.4311121f, 147f);
                        path.LineTo(114.568946f, 147f);
                        path.CubicTo(117.323748f, 146.994143f, 120.020241f, 145.426228f, 121.407172f, 143.034271f);
                        path.LineTo(142.976161f, 105.465744f);
                        path.CubicTo(144.34135f, 103.067402f, 144.341209f, 99.9325978f, 142.976161f, 97.5342563f);
                        path.LineTo(121.407172f, 59.965729f);
                        path.CubicTo(120.020241f, 57.5737917f, 117.323748f, 56.0054182f, 114.568946f, 56f);
                        path.LineTo(71.4311121f, 56f);
                        path.Close();

                        // draw the Xamagon path
                        canvas.DrawPath(path, paint);
                    } // End Using path


                    // ClipDeviceBounds not ClipBounds
                    canvas.DrawLine(0, 0, canvas.ClipDeviceBounds.Width, canvas.ClipDeviceBounds.Height, paint);
                    canvas.DrawLine(0, canvas.ClipDeviceBounds.Height, canvas.ClipDeviceBounds.Width, 0, paint);

                    canvas.DrawLine(0 + 1, 0, 0 + 1, canvas.ClipDeviceBounds.Height, paint);

                    canvas.DrawLine(0, surface.Canvas.ClipDeviceBounds.Height / 2, canvas.ClipDeviceBounds.Width, canvas.ClipDeviceBounds.Height / 2, paint);

                    canvas.DrawLine(canvas.ClipDeviceBounds.Width - 1, 0 + 1, canvas.ClipDeviceBounds.Width - 1, canvas.ClipDeviceBounds.Height, paint);
                } // End Using paint


                // Your drawing code goes here.
                // surface.Snapshot().Encode(SKImageEncodeFormat.Webp, 80);
                // SKData p = surface.Snapshot().Encode();
                SKData p = surface.Snapshot().Encode(SKImageEncodeFormat.Png, 80);
                // p.SaveTo()



                using (System.IO.MemoryStream ms = new System.IO.MemoryStream(p.ToArray()))
                {
                    this.pictureBox1.Image = System.Drawing.Image.FromStream(ms);
                } // End Using ms

                System.IO.File.WriteAllBytes(MapProjectPath("~testme.png"), p.ToArray());
            } // End Using surface

            // this.Close();
        } // End Sub
Пример #45
0
 public static SKColorFilter CreateXferMode(SKColor c, SKXferMode mode)
 {
     return(GetObject <SKColorFilter>(SkiaApi.sk_colorfilter_new_mode(c, mode)));
 }
Пример #46
0
		public void SetPixel (int x, int y, SKColor color)
		{
			if (ColorType == SKColorType.Index8)
			{
				throw new NotSupportedException ("This method is not supported for bitmaps with ColorTypes of Index8.");
			}
			SkiaApi.sk_bitmap_set_pixel_color (Handle, x, y, color);
		}
Пример #47
0
 public static SKColorFilter CreateLighting(SKColor mul, SKColor add)
 {
     return(GetObject <SKColorFilter>(SkiaApi.sk_colorfilter_new_lighting(mul, add)));
 }
Пример #48
0
		public static SKImageFilter CreateDropShadow(float dx, float dy, float sigmaX, float sigmaY, SKColor color, SKDropShadowImageFilterShadowMode shadowMode, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null)
		{
			return GetObject<SKImageFilter>(SkiaApi.sk_imagefilter_new_drop_shadow(dx, dy, sigmaX, sigmaY, color, shadowMode, input == null ? IntPtr.Zero : input.Handle, cropRect == null ? IntPtr.Zero : cropRect.Handle));
		}
Пример #49
0
		public extern static sk_imagefilter_t sk_imagefilter_new_point_lit_diffuse(ref SKPoint3 location, SKColor lightColor, float surfaceScale, float kd, sk_imagefilter_t input /*NULL*/, sk_imagefilter_croprect_t cropRect /*NULL*/);
Пример #50
0
		public static SKImageFilter CreateSpotLitDiffuse(SKPoint3 location, SKPoint3 target, float specularExponent, float cutoffAngle, SKColor lightColor, float surfaceScale, float kd, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null)
		{
			return GetObject<SKImageFilter>(SkiaApi.sk_imagefilter_new_spot_lit_diffuse(ref location, ref target, specularExponent, cutoffAngle, lightColor, surfaceScale, kd, input == null ? IntPtr.Zero : input.Handle, cropRect == null ? IntPtr.Zero : cropRect.Handle));
		}
Пример #51
0
		public extern static sk_imagefilter_t sk_imagefilter_new_point_lit_specular(ref SKPoint3 location, SKColor lightColor, float surfaceScale, float ks, float shininess, sk_imagefilter_t input /*NULL*/, sk_imagefilter_croprect_t cropRect /*NULL*/);
Пример #52
0
 public SKColorTable(SKColor[] colors)
     : this(colors, colors.Length)
 {
 }
Пример #53
0
		public extern static sk_imagefilter_t sk_imagefilter_new_spot_lit_specular(ref SKPoint3 location, ref SKPoint3 target, float specularExponent, float cutoffAngle, SKColor lightColor, float surfaceScale, float ks, float shininess, sk_imagefilter_t input /*NULL*/, sk_imagefilter_croprect_t cropRect /*NULL*/);
Пример #54
0
 public void DrawColor(SKColor color, SKXferMode mode = SKXferMode.Src)
 {
     SkiaApi.sk_canvas_draw_color (Handle, color, mode);
 }
Пример #55
0
		public extern static sk_colorfilter_t sk_colorfilter_new_mode(SKColor c, SKXferMode mode);
Пример #56
0
        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?
                    var shader = SKShader.CreateLinearGradient(start, end, stopColors, stopOffsets, tileMode);
                    paint.Shader = shader;
                    shader.Dispose();
                }
                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?
                        var shader = SKShader.CreateRadialGradient(center, radius, stopColors, stopOffsets, tileMode);
                        paint.Shader = shader;
                        shader.Dispose();
                    }
                }

                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;
                paint.Shader = SKShader.CreateBitmap(bitmap.Bitmap, tileX, tileY, translation);
                paint.Shader.Dispose();
            }

            return rv;
        }
Пример #57
0
		public extern static sk_colorfilter_t sk_colorfilter_new_lighting(SKColor mul, SKColor add);
Пример #58
0
        public static bool TryParse(string hexString, out SKColor color)
        {

            if (hexString == null)
            {
                // error
                color = SKColor.Empty;
                return false;
            } 
            // clean up string
            hexString = hexString.Trim().ToUpperInvariant();
            if (hexString == "")
            {
                color = SKColor.Empty;
                return false;
            }

            if (hexString[0] == '#')
                hexString = hexString.Substring(1);

            var len = hexString.Length;
            if (len == 3 || len == 4)
            {
                byte a, r, g, b;
                // parse [A]
                if (len == 4)
                {
                    if (!byte.TryParse(string.Concat(hexString[len - 4], hexString[len - 4]), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out a))
                    {
                        // error
                        color = SKColor.Empty;
                        return false;
                    }
                }
                else
                {
                    a = 255;
                }

                // parse RGB
                if (!byte.TryParse(string.Concat(hexString[len - 3], hexString[len - 3]), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out r) ||
                    !byte.TryParse(string.Concat(hexString[len - 2], hexString[len - 2]), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out g) ||
                    !byte.TryParse(string.Concat(hexString[len - 1], hexString[len - 1]), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out b))
                {
                    // error
                    color = SKColor.Empty;
                    return false;
                }

                // success
                color = new SKColor(r, g, b, a);
                return true;
            }

            if (len == 6 || len == 8)
            {
                // parse [AA]RRGGBB
                uint number;
                if (!uint.TryParse(hexString, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out number))
                {
                    // error
                    color = SKColor.Empty;
                    return false;
                }

                // success
                color = (SKColor)number;

                // alpha was not provided, so use 255
                if (len == 6)
                {
                    color = color.WithAlpha(255);
                }
                return true;
            }

            // error
            color = SKColor.Empty;
            return false;
        }
Пример #59
0
 public void DrawPoint(float x, float y, SKColor color)
 {
     SkiaApi.sk_canvas_draw_point_color(Handle, x, y, color);
 }