'Drawing an Arc with a linear gradient brush using Microsoft Maui Graphics
I'm having difficulty drawing a gradient colored arc with Microsoft Maui Graphics.
I'm using Windows Forms, Visual Studio Preview 5, and .NET Core 6.
Here is what I have tried:
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Graphics.Skia;
using System;
using System.Windows.Forms;
namespace MauiWinForms {
public partial class Form1:Form {
public Form1() {
InitializeComponent();
}
private void skglControl1_PaintSurface(object sender, SkiaSharp.Views.Desktop.SKPaintGLSurfaceEventArgs e) {
ICanvas canvas = new SkiaCanvas() { Canvas = e.Surface.Canvas };
var canvasWidth = skglControl1.Width = 800;
var canvasHeight = skglControl1.Height = 800;
canvas.FillColor = Colors.LightGrey;
canvas.FillRectangle(0, 0, canvasWidth, canvasHeight);
canvas.StrokeColor = Colors.Red;
canvas.DrawRectangle(1, 1, 800-2, 800-2);
var centerX = canvasWidth / 2;
var centerY = canvasHeight / 2;
canvas.StrokeColor = Colors.Teal;
canvas.StrokeSize = 10;
var X = centerX - 200;
canvas.DrawArc(X, 0, 400, 400, 0, 90, false, false);
var linearGradientPaint = new LinearGradientPaint {
StartColor = Colors.White,
EndColor = Colors.Green,
StartPoint = new Point(0, 0),
EndPoint = new Point(1, 0)
};
var myRectangle = new RectangleF(X, 0, 410, 410);
canvas.SetFillPaint(linearGradientPaint, myRectangle);
canvas.DrawArc(X, 0, 400, 400, 0, -90, false, false);
}
private void skglControl1_SizeChanged(object sender, EventArgs e) => skglControl1.Invalidate();
}
}
And this is what I get:
As you can see, the linear gradient is not applied. Any help will be greatly appreciated.
Charles
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

