gpt4 book ai didi

c# - 我可以在 Xamarin 项目的 XAML 中绘制圆形、椭圆或正方形吗?

转载 作者:行者123 更新时间:2023-12-04 13:43:09 26 4
gpt4 key购买 nike

很好,我想在 Xamarin 项目中绘制圆形、正方形、椭圆和三角形,但我找不到如何在 UWP 中这样做:

<StackPanel>
<Ellipse Fill="Yellow"
Height="100"
Width="200"
StrokeThickness="2"
Stroke="Black"/>
</StackPanel>

问题是我不知道我是否需要 NuGet 包或 Xamarin 中的一些补充包

最佳答案

如果要画圆(只能通过代码实现),可以引用下面的代码。

public class SimpleCirclePage : ContentPage
{
public SimpleCirclePage()
{


SKCanvasView canvasView = new SKCanvasView();
canvasView.PaintSurface += OnCanvasViewPaintSurface;
Content = canvasView;
}

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

canvas.Clear();

SKPaint paint = new SKPaint
{
Style = SKPaintStyle.Stroke,
Color = Color.Red.ToSKColor(),
StrokeWidth = 10
};
canvas.DrawCircle(info.Width / 3, info.Height / 2, 100, paint);

}
}

详情: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/graphics/skiasharp/basics/circle

如果你想使用XAML和代码来绘制椭圆,你可以引用下面的代码。

在 XAML 中
 <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:skia="clr- namespace:SkiaSharp.Views.Forms;assembly=SkiaSharp.Views.Forms"
x:Class="SkiaSharpFormsDemos.Basics.EllipseFillPage"
Title="Ellipse Fill">

<skia:SKCanvasView PaintSurface="OnCanvasViewPaintSurface" />

代码
public partial class EllipseFillPage : ContentPage
{
public EllipseFillPage()
{
InitializeComponent();
}

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

canvas.Clear();

float strokeWidth = 5;
float xRadius = (info.Width - strokeWidth) / 3;
float yRadius = (info.Height - strokeWidth) / 3;

SKPaint paint = new SKPaint
{
Style = SKPaintStyle.Stroke,
Color = SKColors.Black,
StrokeWidth = strokeWidth
};
canvas.DrawOval(info.Width / 2, info.Height / 2, xRadius, yRadius, paint);
}
}

如果您想绘制仅使用 XAML 的锐线方式(如在 UWP 中),您可以下载 this plugin .

关于c# - 我可以在 Xamarin 项目的 XAML 中绘制圆形、椭圆或正方形吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53871872/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com