我在Xamarin.Form应用程序的StackLayout中有一个SkiaCanvasView和一个Label,试图频繁更新屏幕上的位图,但它只能绘制一次。 XAML文件和CS代码如下所示,
<StackLayout
x:Name="stackMonitors"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand">
<Label x:Name="numCounter"
Text="counter"
VerticalOptions="Start"/>
<skia:SKCanvasView x:Name="canvasView"
PaintSurface="OnCanvasView_PaintSurface"
VerticalOptions ="FillAndExpand"
Margin="10,10,0,10"/>
</StackLayout>
SKBitmap skiBMP = new SKBitmap();
SKSurface skiSurface;
SKCanvas skiCanvas;
SKPaint skiPaint = new SKPaint();
SKRect skiRect = new SKRect();
int temp = 0;
private void OnCanvasView_PaintSurface(object sender, SKPaintSurfaceEventArgs e)
{
numCounter.Text = (++temp).ToString(); //if the PaintSurface is called more than once automatically, the numCounter should not be "1" all the time
skiSurface = e.Surface;
skiCanvas = skiSurface.Canvas;
skiRect.Top = 0;
skiRect.Left = 0;
skiRect.Right = e.Info.Width;
skiRect.Bottom = e.Info.Width * 0.5625f;
skiBMP = SKBitmap.Decode(myOperator.PCImageMemoryStream); //Bitmap stream updates 30 times per second
skiCanvas.DrawBitmap(skiBMP, skiRect, skiPaint);
}
预期结果
myOperator.PCImageMemoryStream的值不断更新,我预计OnCanvasView_PaintSurface事件将每秒自动触发60次,因此CanvasView可以非常频繁地在MainPage上绘制myOperator.PCImageMemoryStream。
实际结果
但是,它只绘制一次,标签“ numCounter”在运行该应用程序后始终显示为“ 1”。
摘要
我不知道如何在OnCanvasView_PaintSurface每次可以称为设备屏幕刷新。微软Skia网络研讨会表示,Skia CanvasView每秒可涂漆60次...
(什么是坏的是,在该项目采取SkiaSharp的参考之后,XAML文件无法正常预览...)
非常感谢。