コード例 #1
0
        private void Canvas_PaintSurface(object sender, SkiaSharp.Views.Forms.SKPaintSurfaceEventArgs e)
        {
            SKImageInfo info    = e.Info;
            SKSurface   surface = e.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();
            if (character != null)
            {
                Assembly assembly = GetType().GetTypeInfo().Assembly;
                string[] images   = new string[5];
                images[0] = character.Image;
                images[1] = "Betrayal.Resources.overlays.speed_" + currentSpeed + ".png";
                images[2] = "Betrayal.Resources.overlays.might_" + currentMight + ".png";
                images[3] = "Betrayal.Resources.overlays.sanity_" + currentSanity + ".png";
                images[4] = "Betrayal.Resources.overlays.knowledge_" + currentKnowledge + ".png";

                foreach (string s in images)
                {
                    if (!string.IsNullOrWhiteSpace(s))
                    {
                        using (Stream stream = assembly.GetManifestResourceStream(s))
                        {
                            SKBitmap resourceBitmap = SKBitmap.Decode(stream);
                            SKRectI  pictureFrame   = info.Rect;
                            SKSizeI  imageSize      = resourceBitmap.Info.Size;
                            SKRectI  dest           = pictureFrame.AspectFit(imageSize); // fit the size inside the rect

                            // draw the image
                            SKPaint paint = new SKPaint
                            {
                                FilterQuality = SKFilterQuality.High // high quality scaling
                            };
                            canvas.DrawBitmap(resourceBitmap, dest, paint);
                        }
                    }
                }
                EnableControls();
            }
        }