コード例 #1
0
        private UniImage RenderWithCrop(SKImage maskedImage, FixedCameraEnhancedData configuration)
        {
            var mask = GenerateHomographyMask(configuration, _width, _height);

            SKImage maskedCroppedImage;

            using (var tempSurface = SKSurface.Create(new SKImageInfo(_croppedSize.Width, _croppedSize.Height)))
            {
                //get the drawing canvas of the surface
                var canvas = tempSurface.Canvas;

                //set background color
                canvas.Clear(SKColors.Transparent);

                canvas.DrawImage(maskedImage, SKRect.Create(_minX.Value, _minY.Value, _croppedSize.Width, _croppedSize.Height), SKRect.Create(0, 0, _croppedSize.Width, _croppedSize.Height));

                canvas.DrawImage(mask, 0, 0);

                // return the surface as a manageable image
                maskedCroppedImage = tempSurface.Snapshot();
            }

            //

            var image = SKImageIntoUniImage(maskedCroppedImage);

            maskedCroppedImage.Dispose();

            return(image);
        }
コード例 #2
0
        private SKPoint[][] GetPolygons(FixedCameraEnhancedData configuration, int sourceWidth, int sourceHeight)
        {
            var polygons = configuration.Layers.OfType <HyperTagFixedCameraEnhancedDataLayer>()
                           .SelectMany(x => x.Tags ?? new HyperTag[0])
                           .Select(x => ProcessHyperTag(x, sourceWidth, sourceHeight))
                           .Where(x => x != null)
                           .ToArray();

            return(polygons);
        }
コード例 #3
0
        private UniImage RenderWithNoCutoff(SKImage maskedImage, FixedCameraEnhancedData configuration)
        {
            var polygons = GetPolygons(configuration, _width, _height);

            SKImage maskedCroppedImage;

            using (var tempSurface = SKSurface.Create(new SKImageInfo(maskedImage.Width, maskedImage.Height)))
            {
                //get the drawing canvas of the surface
                var canvas = tempSurface.Canvas;

                //set background color
                canvas.Clear(SKColors.Transparent);

                canvas.DrawImage(maskedImage, 0, 0);

                var fillPaint = new SKPaint
                {
                    Style       = SKPaintStyle.Stroke,
                    Color       = SKColors.Red,
                    BlendMode   = SKBlendMode.Src,
                    StrokeWidth = 3
                };

                using (fillPaint)
                {
                    var path = new SKPath();
                    foreach (var points in polygons)
                    {
                        path.MoveTo(points.First());
                        for (var i = 1; i < points.Length; i++)
                        {
                            path.LineTo(points[i]);
                        }
                        path.LineTo(points[0]);
                    }

                    canvas.DrawPath(path, fillPaint);
                }

                // return the surface as a manageable image
                maskedCroppedImage = tempSurface.Snapshot();
            }

            //

            var image = SKImageIntoUniImage(maskedCroppedImage);

            maskedCroppedImage.Dispose();

            return(image);
        }
コード例 #4
0
        private SKImage GenerateHomographyMask(FixedCameraEnhancedData configuration, int sourceWidth, int sourceHeight)
        {
            var polygons = GetPolygons(configuration, sourceWidth, sourceHeight);

            using (var tempSurface = SKSurface.Create(new SKImageInfo(sourceWidth, sourceHeight)))
            {
                //get the drawing canvas of the surface
                var canvas = tempSurface.Canvas;

                canvas.Clear(SKColors.Black);

                var fillPaint = new SKPaint
                {
                    Style     = SKPaintStyle.Fill,
                    Color     = SKColors.Transparent,
                    BlendMode = SKBlendMode.Clear
                };

                using (fillPaint)
                {
                    var path = new SKPath();
                    foreach (var points in polygons)
                    {
                        path.MoveTo(points.First());
                        for (var i = 1; i < points.Length; i++)
                        {
                            path.LineTo(points[i]);
                        }
                    }

                    canvas.DrawPath(path, fillPaint);
                }

                using (var image = tempSurface.Snapshot())
                {
                    _croppedSize = new Size(_maxX.Value - _minX.Value, _maxY.Value - _minY.Value);

                    var croppingRectI = SKRectI.Create(_minX.Value, _minY.Value, _croppedSize.Width, _croppedSize.Height);

                    var mask = image.Subset(croppingRectI);

                    return(mask);
                }
            }
        }