コード例 #1
0
        public override void Awake(NSObject context)
        {
            base.Awake(context);

            var scale = WKInterfaceDevice.CurrentDevice.ScreenScale;

            var bitmap = new SKBitmap((int)(ContentFrame.Width * scale), (int)(ContentFrame.Height * scale));

            var colors = new[] { SKColors.Cyan, SKColors.Magenta, SKColors.Yellow, SKColors.Cyan };
            var center = new SKPoint(bitmap.Width / 2, bitmap.Height / 2);

            using (var canvas = new SKCanvas(bitmap))
            {
                canvas.Clear(SKColors.Transparent);

                using (var path = new SKPath())
                {
                    path.AddRoundedRect(new SKRect(5, 5, bitmap.Width - 5, bitmap.Height - 5), 5, 5);
                    canvas.ClipPath(path);
                }

                using (var paint = new SKPaint())
                    using (var gradient = SKShader.CreateSweepGradient(center, colors, null))
                    {
                        paint.IsAntialias = true;
                        paint.Shader      = gradient;
                        canvas.DrawPaint(paint);
                        paint.Shader = null;
                    }

                using (var paint = new SKPaint())
                    using (var tf = SKTypeface.FromFamilyName("San Fransisco"))
                    {
                        paint.IsAntialias = true;
                        paint.Color       = SKColors.DarkBlue;
                        paint.TextSize    = (float)(20 * scale);
                        paint.TextAlign   = SKTextAlign.Center;
                        paint.Typeface    = tf;

                        canvas.DrawText("SkiaSharp", center.X, (center.Y / 2) + (paint.TextSize / 2), paint);
                    }
            }

            var image = bitmap.ToUIImage(scale, UIKit.UIImageOrientation.Up);

            imageView.SetImage(image);
        }
コード例 #2
0
        /// <summary>
        /// Generates a blended image with a CAM and the desired overlay color
        /// </summary>
        /// <returns>The blended CAMI mage.</returns>
        /// <param name="index">Index.</param>
        /// <param name="color">Color.</param>
        private async Task <UIImage> GenerateBlendedCAMImage(CAM cam, SKColor color)
        {
            // Cancel the previous blending task if there is one
            cancellationTokenSource?.Cancel();

            cancellationTokenSource = new CancellationTokenSource();

            // Dispose of previous blended image
            blendedImage?.Dispose();

            SKBitmap colorMap = await ImageProcessorRunner.GetCAMColorMapTask(
                cam,
                color,
                (int)(InputImage.Size.Width *InputImage.CurrentScale),
                (int)(InputImage.Size.Height *InputImage.CurrentScale),
                cancellationTokenSource.Token
                );

            SKBitmap input           = InputImage.ToSKBitmap();
            SKBitmap blendedSKBitmap = await ImageProcessorRunner.GetOverlayImageTask(
                input,
                colorMap,
                cancellationTokenSource.Token
                );

            // Dispose of temporary SKBitmap
            input.Dispose();

            UIImage blendedUIImage = blendedSKBitmap.ToUIImage();

            // Cleanup the intermediate bitmaps
            colorMap?.Dispose();
            blendedSKBitmap?.Dispose();

            return(blendedUIImage);
        }