SkiaSharp SKbitmap.GetPixel und SKbitmap.SetPixel – Leistung verbessern
unten ist mein aktueller Code
Code: Select all
private void Timer_Tick(object sender, EventArgs e)
{
frameCounter++;
skglControl1.Invalidate();
}
private void skglControl1_PaintSurface(object sender, SKPaintGLSurfaceEventArgs e)
{
e.Surface.Canvas.Clear(SKColor.FromHsl(0, 0, 0));
DrawPlasma(sender, e);
}
private void DrawPlasma(object sender, SKPaintGLSurfaceEventArgs e)
{
//write directly to buffer
unsafe
{
for (int x = 0; x < skWindowWidth; x++)
{
for (int y = 0; y < skWindowHeight; y++)
{
uint* pixelData = (uint*)pixelsPtr;
pixelData[y * screen.Width + x] = (uint)GetPlasmaColor(x, y);
//screen.SetPixel(x, y, GetPlasmaColor(x, y));
}
}
e.Surface.Canvas.DrawBitmap(screen, new SKPoint(0, 0));
}
}
private SKColor GetPlasmaColor(int x, int y)
{
double plasmaValue =
Math.Sin(x * 0.05 + frameCounter * 0.1) +
Math.Sin(y * 0.03 + frameCounter * 0.05) +
Math.Sin((x + y) * 0.04 + frameCounter * 0.08);
SKColor color = new SKColor((byte)(byte)(plasmaValue * (255 - 1)), (byte)(plasmaValue * (30 - 1)), (byte)(plasmaValue * (200 - 1)));
return color;
}
Mobile version