internal static Bitmap ColorizeImage(Bitmap baseImage, Color newColor, SKBlendMode blendMode, byte alpha = 255) { BitmapData data = baseImage.LockBits(new Rectangle(0, 0, baseImage.Width, baseImage.Height), ImageLockMode.WriteOnly, baseImage.PixelFormat); var info = new SKImageInfo(baseImage.Width, baseImage.Height); using (SKSurface surface = SKSurface.Create(info, data.Scan0, baseImage.Width * 4)) using (SKImage image = SKImage.FromPixels(info, data.Scan0, baseImage.Width * 4)) using (var paint = new SKPaint()) { SKColor color = newColor.ToSKColor(); paint.Color = color; paint.BlendMode = SKBlendMode.SrcIn; surface.Canvas.DrawPaint(paint); using (SKImage img2 = surface.Snapshot()) { surface.Canvas.Clear(); paint.BlendMode = blendMode; paint.Color = new SKColor(color.Red, color.Green, color.Blue, alpha); surface.Canvas.DrawImage(image, SKRect.Create(image.Width, image.Height)); surface.Canvas.DrawImage(img2, SKRect.Create(img2.Width, img2.Height), paint); } } baseImage.UnlockBits(data); return(baseImage); }
void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args) { SKImageInfo info = args.Info; SKSurface surface = args.Surface; SKCanvas canvas = surface.Canvas; canvas.Clear(); // Draw bitmap in top half SKRect rect = new SKRect(0, 0, info.Width, info.Height / 2); canvas.DrawBitmap(bitmap, rect, BitmapStretch.Uniform); // Draw bitmap in bottom halr rect = new SKRect(0, info.Height / 2, info.Width, info.Height); canvas.DrawBitmap(bitmap, rect, BitmapStretch.Uniform); // Get values from XAML controls SKBlendMode blendMode = (SKBlendMode)(blendModePicker.SelectedIndex == -1 ? 0 : blendModePicker.SelectedItem); SKColor color = new SKColor((byte)(255 * redSlider.Value), (byte)(255 * greenSlider.Value), (byte)(255 * blueSlider.Value)); // Draw rectangle with blend mode in bottom half using (SKPaint paint = new SKPaint()) { paint.Color = color; paint.BlendMode = blendMode; canvas.DrawRect(rect, paint); } }
public async ValueTask <byte[]> GetBytesWithFilterAsync( int size, string topic = null, SKImageFilter imageFilter = null, SKColorFilter colorFilter = null, SKShader shader = null, SKBlendMode blendMode = SKBlendMode.Overlay) { Trace.WriteLine("Start"); string url; if (string.IsNullOrEmpty(topic)) { url = string.Format(URL_PATTERN_RND, size); } else { url = string.Format(URL_PATTERN, size, topic); } var imageInfo = new SKImageInfo(size, size); using (var http = new HttpClient()) { var image = await http.GetByteArrayAsync(url);//.ConfigureAwait(false); Trace.WriteLine("Downloaded"); using (var outStream = new MemoryStream()) using (var bitmap = SKBitmap.Decode(image, imageInfo)) using (var surface = SKSurface.Create(imageInfo)) using (var paint = new SKPaint()) { SKCanvas canvas = surface.Canvas; canvas.DrawColor(SKColors.White); if (imageFilter != null) { paint.ImageFilter = imageFilter; } if (colorFilter != null) { paint.ColorFilter = colorFilter; } // draw the bitmap through the filter var rect = SKRect.Create(imageInfo.Size); canvas.DrawBitmap(bitmap, rect, paint); if (shader != null) { paint.Shader = shader; paint.BlendMode = blendMode; canvas.DrawPaint(paint); } SKData data = surface.Snapshot().Encode(SKEncodedImageFormat.Jpeg, 80); data.SaveTo(outStream); byte[] manipedImage = outStream.ToArray(); Trace.WriteLine("End"); return(manipedImage); } } }
void draw_wings(SKCanvas canvas, List <SKPoint> wing, bool upper_wing = false) { List <SKBlendMode> modes = new List <SKBlendMode>() { SKBlendMode.ColorBurn, SKBlendMode.Multiply, SKBlendMode.Difference, SKBlendMode.Darken }; SKBlendMode style = RandomUtility.GetRandomElement <SKBlendMode>(modes); //canvas.ResetMatrix(); int canvasCacheTag = canvas.Save(); if (upper_wing) { canvas.Scale(1, -1); } paint.BlendMode = style; //draw_curve_filled( wing ) SkiaSharpUtility.DrawSplineCurve(canvas, paint, wing, true, SKPathFillType.Winding); paint.BlendMode = SKBlendMode.Multiply;// BLEND canvas.Scale(-1, 1); paint.BlendMode = style; // draw_curve_filled(wing) SkiaSharpUtility.DrawSplineCurve(canvas, paint, wing, true, SKPathFillType.Winding); paint.BlendMode = SKBlendMode.Multiply;// BLEND //canvas.ResetMatrix(); canvas.RestoreToCount(canvasCacheTag); }
private SKImage BlendTwoImages(SKBitmap image1, SKImage image2, SKBlendMode blendMode) { using (var tempSurface = SKSurface.Create(new SKImageInfo(_width, _height))) { //get the drawing canvas of the surface var canvas = tempSurface.Canvas; //set background color canvas.Clear(SKColors.Transparent); var skPaint = new SKPaint { BlendMode = blendMode }; canvas.DrawBitmap(image1, 0, 0); canvas.DrawImage(image2, 0, 0, skPaint); // return the surface as a manageable image var res = tempSurface.Snapshot(); //using (var data = res.Encode(SKEncodedImageFormat.Png, 80)) //{ // // save the data to a stream // using (var stream = System.IO.File.OpenWrite(@$"C:/temp/__{(blendMode.ToString())}.png")) // { // data.SaveTo(stream); // } //} return(res); } }
public static SKImageFilter CreateBlendMode(SKBlendMode mode, SKImageFilter background, SKImageFilter foreground = null, SKImageFilter.CropRect cropRect = null) { if (background == null) { throw new ArgumentNullException(nameof(background)); } return(GetObject <SKImageFilter>(SkiaApi.sk_imagefilter_new_xfermode(mode, background.Handle, foreground == null ? IntPtr.Zero : foreground.Handle, cropRect == null ? IntPtr.Zero : cropRect.Handle))); }
public PorterDuffGridPage() { Title = "Porter-Duff Grid"; SKBlendMode[] blendModes = { SKBlendMode.Src, SKBlendMode.Dst, SKBlendMode.SrcOver, SKBlendMode.DstOver, SKBlendMode.SrcIn, SKBlendMode.DstIn, SKBlendMode.SrcOut, SKBlendMode.DstOut, SKBlendMode.SrcATop, SKBlendMode.DstATop, SKBlendMode.Xor, SKBlendMode.Plus, SKBlendMode.Modulate, SKBlendMode.Clear }; Grid grid = new Grid { Margin = new Thickness(5) }; for (int row = 0; row < 4; row++) { grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Star }); } for (int col = 0; col < 3; col++) { grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star }); } for (int i = 0; i < blendModes.Length; i++) { SKBlendMode blendMode = blendModes[i]; int row = 2 * (i / 4); int col = i % 4; Label label = new Label { Text = blendMode.ToString(), HorizontalTextAlignment = TextAlignment.Center }; Grid.SetRow(label, row); Grid.SetColumn(label, col); grid.Children.Add(label); PorterDuffCanvasView canvasView = new PorterDuffCanvasView(blendMode); Grid.SetRow(canvasView, row + 1); Grid.SetColumn(canvasView, col); grid.Children.Add(canvasView); } Content = grid; }
public static SKShader CreateCompose (SKShader shaderA, SKShader shaderB, SKBlendMode mode) { if (shaderA == null) throw new ArgumentNullException (nameof (shaderA)); if (shaderB == null) throw new ArgumentNullException (nameof (shaderB)); return GetObject (SkiaApi.sk_shader_new_blend (mode, shaderA.Handle, shaderB.Handle)); }
public static SKShader CreateCompose(SKShader shaderA, SKShader shaderB, SKBlendMode mode) { if (shaderA == null) { throw new ArgumentNullException(nameof(shaderA)); } if (shaderB == null) { throw new ArgumentNullException(nameof(shaderB)); } return(GetObject <SKShader> (SkiaApi.sk_shader_new_compose_with_mode(shaderA.Handle, shaderB.Handle, mode))); }
public void DrawVertices(SKVertices vertices, SKBlendMode mode, SKPaint paint) { if (vertices == null) { throw new ArgumentNullException(nameof(vertices)); } if (paint == null) { throw new ArgumentNullException(nameof(paint)); } SkiaApi.sk_canvas_draw_vertices(Handle, vertices.Handle, mode, paint.Handle); }
public async ValueTask <IActionResult> GetWithFilterAsync( int size, string topic = null, SKImageFilter imageFilter = null, SKColorFilter colorFilter = null, SKShader shader = null, SKBlendMode blendMode = SKBlendMode.Overlay) { byte[] manipedImage = await GetBytesWithFilterAsync( size, topic, imageFilter, colorFilter, shader, blendMode).ConfigureAwait(false); var response = File(manipedImage, MEDIA_TYPE); return(response); }
void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args) { SKImageInfo info = args.Info; SKSurface surface = args.Surface; SKCanvas canvas = surface.Canvas; canvas.Clear(); canvas.DrawBitmap(bitmap, info.Rect, BitmapStretch.Uniform); // Get blend mode from Picker SKBlendMode blendMode = (SKBlendMode)(blendModePicker.SelectedIndex == -1 ? 0 : blendModePicker.SelectedItem); using (SKPaint paint = new SKPaint()) { paint.Color = color; paint.BlendMode = blendMode; canvas.DrawRect(info.Rect, paint); } }
public async Task drawGaugeAsync() { // Radial Gauge Constants int uPadding = 150; int side = 500; int radialGaugeWidth = 55; // Line TextSize inside Radial Gauge int lineSize1 = 220; int lineSize2 = 70; int lineSize3 = 80; int lineSize4 = 100; // Line Y Coordinate inside Radial Gauge int lineHeight1 = 70; int lineHeight2 = 170; int lineHeight3 = 270; int lineHeight4 = 370; int lineHeight5 = 530; // Start & End Angle for Radial Gauge float startAngle = -220; float sweepAngle = 260; try { // Getting Canvas Info SKImageInfo info = args.Info; SKSurface surface = args.Surface; SKCanvas canvas = surface.Canvas; progressUtils.setDevice(info.Height, info.Width); canvas.Clear(); SKBlendMode blend = SKBlendMode.SrcIn; canvas.DrawColor(Color.White.ToSKColor(), blend); // Getting Device Specific Screen Values // ------------------------------------------------- // Top Padding for Radial Gauge float upperPading = progressUtils.getFactoredHeight(uPadding); /* Coordinate Plotting for Radial Gauge * * (X1,Y1) ------------ * | (XC,YC) | * | . | * Y | | * | | * ------------ (X2,Y2)) * X * * To fit a perfect Circle inside --> X==Y * i.e It should be a Square */ // Xc & Yc are center of the Circle int Xc = info.Width / 2; float Yc = progressUtils.getFactoredHeight(side); // X1 Y1 are lefttop cordiates of rectange int X1 = (int)(Xc - Yc); int Y1 = (int)(Yc - Yc + upperPading); // X2 Y2 are rightbottom cordiates of rectange int X2 = (int)(Xc + Yc); int Y2 = (int)(Yc + Yc + upperPading); //Loggig Screen Specific Calculated Values Debug.WriteLine("INFO " + info.Width + " - " + info.Height); Debug.WriteLine(" C : " + upperPading + " " + info.Height); Debug.WriteLine(" C : " + Xc + " " + Yc); Debug.WriteLine("XY : " + X1 + " " + Y1); Debug.WriteLine("XY : " + X2 + " " + Y2); // Empty Gauge Styling SKPaint paint1 = new SKPaint { Style = SKPaintStyle.Stroke, Color = Color.FromHex("#e0dfdf").ToSKColor(), // Colour of Radial Gauge StrokeWidth = progressUtils.getFactoredWidth(radialGaugeWidth), // Width of Radial Gauge StrokeCap = SKStrokeCap.Round // Round Corners for Radial Gauge }; // Filled Gauge Styling SKPaint paint2 = new SKPaint { Style = SKPaintStyle.Stroke, Color = Color.FromHex("#05c782").ToSKColor(), // Overlay Colour of Radial Gauge StrokeWidth = progressUtils.getFactoredWidth(radialGaugeWidth), // Overlay Width of Radial Gauge StrokeCap = SKStrokeCap.Round // Round Corners for Radial Gauge }; // Defining boundaries for Gauge SKRect rect = new SKRect(X1, Y1, X2, Y2); //canvas.DrawRect(rect, paint1); //canvas.DrawOval(rect, paint1); // Rendering Empty Gauge SKPath path1 = new SKPath(); path1.AddArc(rect, startAngle, sweepAngle); canvas.DrawPath(path1, paint1); // Rendering Filled Gauge SKPath path2 = new SKPath(); path2.AddArc(rect, startAngle, (float)sweepAngleSlider.Value); canvas.DrawPath(path2, paint2); //---------------- Drawing Text Over Gauge --------------------------- // Achieved Minutes using (SKPaint skPaint = new SKPaint()) { skPaint.Style = SKPaintStyle.Fill; skPaint.IsAntialias = true; skPaint.Color = SKColor.Parse("#676a69"); skPaint.TextAlign = SKTextAlign.Center; skPaint.TextSize = progressUtils.getFactoredHeight(lineSize1); skPaint.Typeface = SKTypeface.FromFamilyName( "Arial", SKFontStyleWeight.Bold, SKFontStyleWidth.Normal, SKFontStyleSlant.Upright); // Drawing Achieved Minutes Over Radial Gauge // if (sw_listToggle.IsToggled) // canvas.DrawText(chartvalue + "", Xc, Yc + progressUtils.getFactoredHeight(lineHeight1), skPaint); // else // canvas.DrawText(dailyWorkout + "", Xc, Yc + progressUtils.getFactoredHeight(lineHeight1), skPaint); } // Achieved Minutes Text Styling using (SKPaint skPaint = new SKPaint()) { skPaint.Style = SKPaintStyle.Fill; skPaint.IsAntialias = true; skPaint.Color = SKColor.Parse("#676a69"); skPaint.TextAlign = SKTextAlign.Center; skPaint.TextSize = progressUtils.getFactoredHeight(lineSize2); // canvas.DrawText("Seconds", Xc, Yc + progressUtils.getFactoredHeight(lineHeight2), skPaint); } // Goal Minutes Text Styling using (SKPaint skPaint = new SKPaint()) { skPaint.Style = SKPaintStyle.Fill; skPaint.IsAntialias = true; skPaint.Color = SKColor.Parse("#e2797a"); skPaint.TextAlign = SKTextAlign.Center; skPaint.TextSize = progressUtils.getFactoredHeight(lineSize3); skPaint.Typeface = SKTypeface.FromFamilyName( "Arial", SKFontStyleWeight.Bold, SKFontStyleWidth.Normal, SKFontStyleSlant.Upright); // Drawing Text Over Radial Gauge // if (sw_listToggle.IsToggled) // canvas.DrawText(DateTime.Now.ToString("dddd, dd'-'MM'-'yyyy"), Xc, Yc + progressUtils.getFactoredHeight(lineHeight3), skPaint); //else { // canvas.DrawText("Goal " + goal / 30 + " Min", Xc, Yc + progressUtils.getFactoredHeight(lineHeight3), skPaint); } } // Goal Minutes Text Styling using (SKPaint skPaint = new SKPaint()) { skPaint.Style = SKPaintStyle.Fill; skPaint.IsAntialias = true; skPaint.Color = SKColor.Parse("#e2797a"); skPaint.TextAlign = SKTextAlign.Center; skPaint.TextSize = progressUtils.getFactoredHeight(lineSize3); skPaint.Typeface = SKTypeface.FromFamilyName( "Arial", SKFontStyleWeight.Bold, SKFontStyleWidth.Normal, SKFontStyleSlant.Upright); // Drawing Text Over Radial Gauge // if (sw_listToggle.IsToggled) // canvas.DrawText(DateTime.Now.ToString("HH:mm:ss"), Xc, Yc + progressUtils.getFactoredHeight(lineHeight4), skPaint); //else { // canvas.DrawText("Goal " + goal / 30 + " Min", Xc, Yc + progressUtils.getFactoredHeight(lineHeight3), skPaint); } } // Goal Minutes Text Styling using (SKPaint skPaint = new SKPaint()) { skPaint.Style = SKPaintStyle.Fill; skPaint.IsAntialias = true; skPaint.Color = SKColor.Parse("#676a69"); skPaint.TextAlign = SKTextAlign.Center; skPaint.TextSize = progressUtils.getFactoredHeight(lineSize4); skPaint.Typeface = SKTypeface.FromFamilyName( "Arial", SKFontStyleWeight.Bold, SKFontStyleWidth.Normal, SKFontStyleSlant.Upright); // Drawing Text Over Radial Gauge // if (sw_listToggle.IsToggled) canvas.DrawText("Battery " + Chartvalue + "%", Xc, Yc + progressUtils.getFactoredHeight(lineHeight5), skPaint); //else { // canvas.DrawText("Goal " + goal / 30 + " Min", Xc, Yc + progressUtils.getFactoredHeight(lineHeight3), skPaint); } } } catch (Exception e) { Debug.WriteLine(e.StackTrace); } }
public void DrawVertices(SKVertices vertices, SKBlendMode mode, SKPaint paint) { if (vertices == null) throw new ArgumentNullException(nameof(vertices)); }
public void DrawVertices(SKVertexMode vmode, SKPoint[] vertices, SKPoint[] texs, SKColor[] colors, SKBlendMode mode, UInt16[] indices, SKPaint paint) { var vert = SKVertices.CreateCopy(vmode, vertices, texs, colors, indices); DrawVertices(vert, mode, paint); }
public SKImage RenderSkia(IEnumerable <HeatPoint> points, int width, int height, ClassificationSettings[] settings, SKBlendMode blendMode = SKBlendMode.Plus) { throw new NotImplementedException(); }
public static SKColorFilter CreateBlendMode(SKColor c, SKBlendMode mode) { return GetObject<SKColorFilter>(SkiaApi.sk_colorfilter_new_mode(c, (SKXferMode)mode)); }
public static SKImageFilter CreateMerge(SKImageFilter first, SKImageFilter second, SKBlendMode mode, SKImageFilter.CropRect cropRect = null) { return(CreateMerge(new [] { first, second }, new [] { mode, mode }, cropRect)); }
public void DrawVertices(SKVertexMode vmode, SKPoint[] vertices, SKPoint[] texs, SKColor[] colors, SKBlendMode mode, UInt16[] indices, SKPaint paint) { if (vertices == null) { throw new ArgumentNullException(nameof(vertices)); } if (paint == null) { throw new ArgumentNullException(nameof(paint)); } if (texs != null && vertices.Length != texs.Length) throw new ArgumentException("The number of texture coordinates must match the number of vertices.", nameof(texs)); }
public static SKImageFilter CreateBlendMode(SKBlendMode mode, SKImageFilter background, SKImageFilter foreground = null, SKImageFilter.CropRect cropRect = null) { if (background == null) throw new ArgumentNullException(nameof(background)); return GetObject<SKImageFilter>(SkiaApi.sk_imagefilter_new_xfermode(mode, background.Handle, foreground == null ? IntPtr.Zero : foreground.Handle, cropRect == null ? IntPtr.Zero : cropRect.Handle)); }
public void DrawAtlas(SKImage atlas, SKRect[] sprites, SKRotationScaleMatrix[] transforms, SKColor[] colors, SKBlendMode mode, SKRect cullRect, SKPaint paint) => DrawAtlas(atlas, sprites, transforms, colors, mode, &cullRect, paint);
public extern static void sk_canvas_draw_color(sk_canvas_t t, SKColor color, SKBlendMode mode);
public void set_blend_mode(SKBlendMode blend_mode) { blend_mode_ = blend_mode; }
public PorterDuffCanvasView(SKBlendMode blendMode) { this.blendMode = blendMode; }
public extern static void sk_paint_set_blendmode(sk_paint_t t, SKBlendMode mode);
public extern static sk_imagefilter_t sk_imagefilter_new_xfermode(SKBlendMode mode, sk_imagefilter_t background, sk_imagefilter_t foreground /*NULL*/, sk_imagefilter_croprect_t cropRect /*NULL*/);
public static Tuple <SKPaint, IEnumerable <IDisposable> > CreatePaint(this XInkStroke stroke, SKPaintStyle paintStyle = SKPaintStyle.Stroke, SKBlendMode blendMode = SKBlendMode.SrcATop) { if (stroke == null) { throw new ArgumentNullException(nameof(stroke)); } var disposables = new List <IDisposable>(); SKShader shader = null; if (stroke.DrawingAttributes.Kind == XInkDrawingAttributesKind.Pencil) { var perlin = SKShader.CreatePerlinNoiseFractalNoise(0.01f, 0.01f, 1, 1.0f); var color = SKShader.CreateColor(stroke.DrawingAttributes.Color.ToSKColor().WithAlpha(0x7F)); disposables.Add(perlin); disposables.Add(color); shader = SKShader.CreateCompose( perlin, color, blendMode); } Tuple <SKPaint, IEnumerable <IDisposable> > tuple = null; SKPaint paint = null; if (!stroke.DrawingAttributes.IgnorePressure) { paintStyle = SKPaintStyle.Fill; } try { paint = new SKPaint { Color = stroke.DrawingAttributes.Kind == XInkDrawingAttributesKind.Default ? stroke.DrawingAttributes.Color.ToSKColor() : new SKColor(), StrokeWidth = stroke.DrawingAttributes.IgnorePressure? stroke.DrawingAttributes.Size : 0.0f, Style = paintStyle, IsAntialias = true, StrokeCap = stroke.DrawingAttributes.PenTip == Inking.XPenTipShape.Circle ? SKStrokeCap.Round : SKStrokeCap.Butt, PathEffect = SKPathEffect.CreateCorner(100) }; if (shader != null) { paint.Shader = shader; } tuple = Tuple.Create(paint, disposables as IEnumerable <IDisposable>); paint = null; } finally { paint?.Dispose(); } return(tuple); }
private void DrawAtlas(SKImage atlas, SKRect[] sprites, SKRotationScaleMatrix[] transforms, SKColor[] colors, SKBlendMode mode, SKRect *cullRect, SKPaint paint) { if (atlas == null) { throw new ArgumentNullException(nameof(atlas)); } if (sprites == null) { throw new ArgumentNullException(nameof(sprites)); } if (transforms == null) { throw new ArgumentNullException(nameof(transforms)); } if (transforms.Length != sprites.Length) throw new ArgumentException("The number of transforms must match the number of sprites.", nameof(transforms)); }
public void DrawColor(SKColor color, SKBlendMode mode = SKBlendMode.Src) { SkiaApi.sk_canvas_draw_color(Handle, color, mode); }
public static SKColorFilter CreateBlendMode(SKColor c, SKBlendMode mode) { return(GetObject <SKColorFilter>(SkiaApi.sk_colorfilter_new_mode(c, mode))); }
private void DrawAtlas(SKImage atlas, SKRect[] sprites, SKRotationScaleMatrix[] transforms, SKColor[] colors, SKBlendMode mode, SKRect *cullRect, SKPaint paint) { if (atlas == null) { throw new ArgumentNullException(nameof(atlas)); } if (sprites == null) { throw new ArgumentNullException(nameof(sprites)); } if (transforms == null) throw new ArgumentNullException(nameof(transforms)); }
public void DrawColor (SKColor color, SKBlendMode mode = SKBlendMode.Src) { SkiaApi.sk_canvas_draw_color (Handle, color, mode); }