예제 #1
0
        private void DrawBoundingBox(Image image, AABBBoundingBoxItemWithText boundingBoxWithText)
        {
            const int boundingBoxThickness = 5;
            Random    rand            = new Random();
            IPen      pen             = Pens.Solid(Color.FromRgb((byte)rand.Next(byte.MinValue, byte.MaxValue), (byte)rand.Next(byte.MinValue, byte.MaxValue), (byte)rand.Next(byte.MinValue, byte.MaxValue)), boundingBoxThickness);
            IPath     boundingBoxPath = boundingBoxWithText.BoundingBox.AsRectangularPolygon();

            image.Mutate(context =>
            {
                context.Draw(pen, boundingBoxPath);
                context.DrawText(boundingBoxWithText.Text, _textFont, Color.Black, new PointF(boundingBoxWithText.BoundingBox.Min.X, boundingBoxWithText.BoundingBox.Min.Y - (boundingBoxThickness * 3)));
            });
        }
예제 #2
0
        public static Rgba32 HexToColor(string hexString)
        {
            if (hexString.ToLower() == "transparent")
            {
                return(Color.Transparent);
            }

            try
            {
                var drawingColor = System.Drawing.ColorTranslator.FromHtml("#" + hexString);
                return(Color.FromRgb(drawingColor.R, drawingColor.G, drawingColor.B));
            }
            catch (Exception ex)
            {
            }

            return(Color.FromRgb(254, 254, 254));
        }
예제 #3
0
        public byte[] CreateImage()
        {
            var buildQueue = CreateBuildQueue();

            if (buildQueue == null)
            {
                return(null);
            }

            var cropColours = new List <Rgba32>();

            if (this.CropImage)
            {
                if (this.RenderBackground)
                {
                    cropColours.Add(Color.FromRgb(142, 142, 94));
                    cropColours.Add(Color.FromRgb(152, 152, 101));
                }
                else
                {
                    cropColours.Add(HexToColor(this.RenderCanvasColour));
                }
            }

            using (var canvas = this.DrawingCanvas)
            {
                foreach (var asset in buildQueue)
                {
                    var image = SixLabors.ImageSharp.Image.Load <Rgba32>(asset.GetImagePath());

                    if (asset.Alpha != -1)
                    {
                        TintImage(image, "FFFFFF", (byte)asset.Alpha);
                    }

                    if (asset.ColourCode != null)
                    {
                        TintImage(image, asset.ColourCode, 255);
                    }

                    if (asset.Shadow)
                    {
                        image.Mutate(ctx =>
                        {
                            ctx.Opacity(0.2f);
                        });
                    }

                    var graphicsOptions = new GraphicsOptions();

                    if ((asset.Ink == "ADD" || asset.Ink == "33"))
                    {
                        graphicsOptions.ColorBlendingMode = PixelColorBlendingMode.Add;
                    }
                    else
                    {
                        graphicsOptions.ColorBlendingMode = PixelColorBlendingMode.Normal;
                    }

                    canvas.Mutate(ctx =>
                    {
                        ctx.DrawImage(image, new SixLabors.ImageSharp.Point(canvas.Width - asset.ImageX, canvas.Height - asset.ImageY), graphicsOptions);
                    });
                }


                using (Bitmap tempBitmap = canvas.ToBitmap())
                {
                    if (CropImage && cropColours.Count > 0)
                    {
                        var temp = canvas.ToBitmap();

                        // Crop the image
                        using (Bitmap croppedBitmap = ImageUtil.TrimBitmap(tempBitmap, cropColours.ToArray()))
                        {
                            return(RenderImage(croppedBitmap));
                        }
                    }
                    else
                    {
                        return(RenderImage(tempBitmap));
                    }
                }
            }
        }