コード例 #1
0
ファイル: ZenQuoteImage.cs プロジェクト: Menighin/ZenSource
        private void DrawText(IZenDrawable drawable)
        {
            var FONT_SIZE   = 56;
            var X_TRANSLATE = 40;
            var Y_TRANSLATE = 40;
            var MAX_WIDTH   = 940;
            var MAX_HEIGHT  = 492 - 30; // 30 is for Author name

            var quote = $" {drawable.Message}";

            var textOptions = new TextGraphicsOptions()
            {
                WrapTextWidth = MAX_WIDTH, VerticalAlignment = VerticalAlignment.Center
            };
            var font          = new Font(_font, FONT_SIZE, FontStyle.Bold);
            var currentHeight = 0f;
            var currentWidth  = 0f;

            while (true)
            {
                var renderOptions = new RendererOptions(font, 72)
                {
                    WrappingWidth = textOptions.WrapTextWidth
                };
                var textMeasure = TextMeasurer.Measure(quote, renderOptions);
                currentHeight = textMeasure.Height;
                currentWidth  = textMeasure.Width;

                if (currentHeight >= MAX_HEIGHT)
                {
                    FONT_SIZE -= 8;
                    font       = new Font(_font, FONT_SIZE, FontStyle.Bold);
                }
                else
                {
                    break;
                }
            }

            var yDraw = (MAX_HEIGHT - currentHeight) > Y_TRANSLATE * 2 ? IMAGE_HEIGHT / 2 - Y_TRANSLATE * 2 : IMAGE_HEIGHT / 2;

            //_image.DrawText(quote, font, Brushes.Solid(Rgba32.White), Pens.Solid<Rgba32>(new SolidBrush<Rgba32>(Rgba32.Black), 1), new Vector2(X_TRANSLATE, yDraw), textOptions);
            _image.DrawText(quote, font, Brushes.Solid(Rgba32.White), Pens.Solid(Rgba32.Black, 1), new Vector2(X_TRANSLATE, yDraw), textOptions);

            // Drawing Author name
            textOptions = new TextGraphicsOptions()
            {
                HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Top
            };
            _image.DrawText(drawable.Author, _fontAuthor, Rgba32.White, new Vector2(currentWidth + X_TRANSLATE, yDraw + currentHeight / 2 + 10), textOptions);
        }
コード例 #2
0
ファイル: DrawText.Path.cs プロジェクト: Toxantron/ImageSharp
        public void FillsForEachACharachterWhenBrushSetAndNotPen()
        {
            this.img.DrawText(
                "123",
                this.Font,
                Brushes.Solid(Rgba32.Red),
                null,
                path,
                new TextGraphicsOptions(true));

            Assert.NotEmpty(this.img.ProcessorApplications);
            Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
            Assert.IsType <FillRegionProcessor <Rgba32> >(this.img.ProcessorApplications[0].processor);
        }
コード例 #3
0
        public void FillsForEachACharacterWhenBrushSetAndNotPen()
        {
            this.operations.DrawText(
                new TextGraphicsOptions {
                Antialias = true
            },
                "123",
                this.Font,
                Brushes.Solid(Color.Red),
                null,
                Vector2.Zero);

            this.Verify <DrawTextProcessor>(0);
        }
コード例 #4
0
        public static string GenerateFront(string name, Roles role, string filePath)
        {
            string hexcode = "#0B1133";
            string border  = "Cards/hero_frontoverlay.png";

            if (role == Roles.Villain)
            {
                border  = "Cards/villain_frontoverlay.png";
                hexcode = "#670000";
            }
            else if (role == Roles.Rogue)
            {
                border  = "Cards/rogue_frontoverlay.png";
                hexcode = "#350022";
            }

            var fontCollection = new FontCollection();
            var parentFont     = fontCollection.Install("Cards/front.tff").CreateFont(50, FontStyle.Bold);

            var childFont = parentFont;

            using (Image <Rgba32> backgroundImage = Image.Load(filePath))
            {
                using (Image <Rgba32> borderImage = Image.Load(border))
                {
                    int   fontSize   = 50;
                    float textOffset = 0;
                    while (true)
                    {
                        var size = TextMeasurer.Measure(name, new RendererOptions(childFont));
                        if (size.Width > 350)
                        {
                            fontSize -= 5;
                            childFont = new Font(parentFont, fontSize);
                            continue;
                        }

                        textOffset = 250 - size.Width / 2;
                        break;
                    }
                    backgroundImage.Mutate(x => x.Resize(new ResizeOptions()
                    {
                        Mode = ResizeMode.Crop, Size = new Size(500, 700), Position = AnchorPositionMode.Top
                    }).DrawImage(borderImage, 1).DrawText(name, childFont, Brushes.Solid(Rgba32.FromHex("#FFFFFF")), Pens.Solid(Rgba32.FromHex(hexcode), 8), new PointF(textOffset, 630)).DrawText(name, childFont, Brushes.Solid(Rgba32.FromHex("#FFFFFF")), new PointF(textOffset, 630)));

                    backgroundImage.Save($"Cards/Done/front-{name}.png");
                    return($"Cards/Done/front-{name}.png");
                }
            }
        }
コード例 #5
0
ファイル: DrawText.Path.cs プロジェクト: woutware/ImageSharp
        public void BrushAppliesBeforPen()
        {
            this.operations.DrawText(
                new TextGraphicsOptions(true),
                "1",
                this.Font,
                Brushes.Solid(Rgba32.Red),
                Pens.Dash(Rgba32.Red, 1),
                this.path);

            var processor = this.Verify <FillRegionProcessor <Rgba32> >(0);

            this.Verify <FillRegionProcessor <Rgba32> >(1);
        }
コード例 #6
0
ファイル: DrawText.Path.cs プロジェクト: woutware/ImageSharp
        public void FillsForEachACharachterWhenBrushSetAndNotPen()
        {
            this.operations.DrawText(
                new TextGraphicsOptions(true),
                "123",
                this.Font,
                Brushes.Solid(Rgba32.Red),
                null,
                this.path);

            this.Verify <FillRegionProcessor <Rgba32> >(0);
            this.Verify <FillRegionProcessor <Rgba32> >(1);
            this.Verify <FillRegionProcessor <Rgba32> >(2);
        }
コード例 #7
0
ファイル: DrawText.Path.cs プロジェクト: Toxantron/ImageSharp
        public void BrushAppliesBeforPen()
        {
            this.img.DrawText(
                "1",
                this.Font,
                Brushes.Solid(Rgba32.Red),
                Pens.Dash(Rgba32.Red, 1),
                path,
                new TextGraphicsOptions(true));

            Assert.NotEmpty(this.img.ProcessorApplications);
            Assert.Equal(2, this.img.ProcessorApplications.Count);
            Assert.IsType <FillRegionProcessor <Rgba32> >(this.img.ProcessorApplications[0].processor);
            Assert.IsType <FillRegionProcessor <Rgba32> >(this.img.ProcessorApplications[1].processor);
        }
コード例 #8
0
        public void FillsForEachACharacterWhenBrushSetAndNotPen()
        {
            this.operations.DrawText(
                this.otherTextOptions,
                "123",
                this.Font,
                Brushes.Solid(Color.Red),
                null,
                Vector2.Zero);

            var processor = this.Verify <DrawTextProcessor>(0);

            Assert.NotEqual(this.textOptions, processor.Options.TextOptions);
            Assert.NotEqual(this.options, processor.Options.GraphicsOptions);
        }
コード例 #9
0
        public void BrushAppliesBeforPen()
        {
            this.img.DrawText(
                "1",
                this.Font,
                Brushes.Solid(Color.Red),
                Pens.Dash(Color.Red, 1),
                Vector2.Zero,
                new TextGraphicsOptions(true));

            Assert.NotEmpty(this.img.ProcessorApplications);
            Assert.Equal(2, this.img.ProcessorApplications.Count);
            Assert.IsType <FillRegionProcessor <Color> >(this.img.ProcessorApplications[0].processor);
            Assert.IsType <DrawPathProcessor <Color> >(this.img.ProcessorApplications[1].processor);
        }
コード例 #10
0
        public void OtherShape()
        {
            var imageSize = new Rectangle(0, 0, 500, 500);
            var path      = new EllipsePolygon(1, 1, 23);
            var processor = new FillPathProcessor(new ImageSharp.Drawing.Processing.ShapeGraphicsOptions()
            {
                GraphicsOptions =
                {
                    Antialias = true
                }
            }, Brushes.Solid(Color.Red), path);
            var pixelProcessor = processor.CreatePixelSpecificProcessor <Rgba32>(null, null, imageSize);

            Assert.IsType <FillRegionProcessor <Rgba32> >(pixelProcessor);
        }
コード例 #11
0
ファイル: SpoilersService.cs プロジェクト: Slamerz/DmC
 //External
 public Task <Image <Rgba32> > MakinMemes(string uri, string txt) => Task.Run(async() =>
 {
     var img    = await DownloadImageAsync(uri);
     var brush  = Brushes.Solid <Rgba32>(Rgba32.White);
     var pen    = new Pen <Rgba32>(Rgba32.Black, 3);
     var center = new PointF(1, img.Height / 2);
     _Meme      = _fonts.Find("Impact").CreateFont(img.Width * 0.064f);
     img.DrawText(txt, _Meme, brush, pen, center, new TextGraphicsOptions(true)
     {
         HorizontalAlignment = HorizontalAlignment.Center,
         VerticalAlignment   = VerticalAlignment.Center,
         WrapTextWidth       = img.Width - 40
     });
     return(img);
 }
                                                                              );
コード例 #12
0
        public static Image <Argb32> FlexRender(int spacing, IEnumerable <Image <Argb32> > images)
        {
            var canvas = new Image <Argb32>(Constants.PanelWidth, Constants.PanelHeight);

            canvas.Mutate(c => c.Fill(Brushes.Solid(new Argb32(0, 0, 0, 0))));
            int       x = 0;
            const int y = 0;

            foreach (var image in images)
            {
                canvas.Mutate(c => c.DrawImage(image, new Point(x, y), PixelColorBlendingMode.Normal, 1));
                x += image.Width + spacing;
            }

            return(canvas);
        }
コード例 #13
0
ファイル: EngineAssets.cs プロジェクト: AximoGames/AxEngine
        private static bool CreateImage(string subPath, string cachePath, object options)
        {
            var img = new Image <Rgb24>(512, 512);

            img.Mutate(ctx => ctx.Clear(Color.White));
            var blackBrush = Brushes.Solid(Color.Black);
            var whiteBrush = Brushes.Solid(Color.White);
            var charsX     = "12345678";
            var charsY     = "ABCDEFGH";
            var font       = new Font(SharedLib.DefaultFontFamily(), 56f, FontStyle.Regular);

            for (var y = 0; y < 8; y++)
            {
                for (var x = 0; x < 8; x++)
                {
                    var box   = new Rectangle(x * 64, y * 64, 64, 64);
                    var label = (string)charsY[y].ToString() + charsX[x].ToString();

                    var evenX = x % 2 == 0;
                    var evenY = y % 2 == 0;
                    var black = evenX;
                    if (evenY)
                    {
                        black = !black;
                    }

                    if (black)
                    {
                        img.Mutate(ctx => ctx.Fill(blackBrush, box));
                    }

                    var fontColor = black ? Color.White : Color.Black;

                    var gfxOptions = new TextGraphicsOptions
                    {
                        TextOptions = new TextOptions
                        {
                            VerticalAlignment   = VerticalAlignment.Center,
                            HorizontalAlignment = HorizontalAlignment.Center,
                        },
                    };
                    img.Mutate(ctx => ctx.DrawText(gfxOptions, label, font, fontColor, new PointF(box.X + 32, box.Y + 32)));
                }
            }
            img.Save(cachePath);
            return(true);
        }
コード例 #14
0
        // mark off Y-axis frequency scale.
        public static Image <Rgb24> DrawFreqScale_vertical(int yoffset, int trackHeight, int herzValue, int nyquistFreq)
        {
            double herzPerPixel = nyquistFreq / (double)(trackHeight - yoffset);
            double gridInterval = 1000 / herzPerPixel;
            int    ymark        = trackHeight - (int)Math.Round(herzValue / herzPerPixel);
            int    gridCount    = nyquistFreq / 1000;

            int           xoffset    = 10;
            int           trackWidth = 45;
            Image <Rgb24> bmp        = new Image <Rgb24>(trackWidth, trackHeight);

            bmp.Mutate(g =>
            {
                g.Clear(Color.LightGray);
                g.FillRectangle(Brushes.Solid(Color.Black), xoffset, 0, bmp.Width - 1, bmp.Height - 1);

                Pen grayPen     = new Pen(Color.DarkGray, 1);
                Pen whitePen    = new Pen(Color.White, 1);
                Font stringFont = Drawing.Arial9;
                g.DrawText("Herz", stringFont, Color.Yellow, new PointF(xoffset + 2, 6)); //draw label
                g.DrawText("Scale", stringFont, Color.Yellow, new PointF(xoffset, 19));   //draw label
                g.DrawLine(whitePen, xoffset, yoffset, trackWidth, yoffset);
                g.DrawLine(whitePen, xoffset, yoffset - 1, trackWidth, yoffset - 1);

                // for pixels in the line
                for (int i = 1; i <= gridCount; i++)
                {
                    int y = trackHeight - (int)Math.Round(i * gridInterval);
                    g.DrawLine(whitePen, xoffset, y, trackWidth, y);
                } // end over all pixels

                // draw the current herz mark
                Pen yellowPen = new Pen(Color.Yellow, 1);
                g.DrawLine(yellowPen, xoffset, ymark, trackWidth, ymark);
                g.DrawLine(yellowPen, xoffset, ymark - 1, trackWidth, ymark - 1);
                g.DrawText(herzValue.ToString(), stringFont, Color.White,
                           new PointF(xoffset + 1, ymark - 14)); //draw time

                // g.DrawLine(whitePen, 0, daysInYear + offset, trackWidth, daysInYear + offset);
                // g.DrawLine(whitePen, 0, offset, trackWidth, offset);          //draw lower boundary
                // g.DrawLine(whitePen, duration, 0, duration, trackHeight - 1);//draw right end boundary

                // g.DrawText(title, stringFont, Color.White, new PointF(duration + 4, 3));
            });

            return(bmp);
        }
コード例 #15
0
 public static IImageProcessingContext DrawTextCentered(
     this IImageProcessingContext context,
     string text,
     Font font,
     Color color,
     PointF point) =>
 context.DrawText(
     new TextGraphicsOptions(new GraphicsOptions(), new TextOptions()
 {
     HorizontalAlignment = HorizontalAlignment.Center
 }),
     text,
     font,
     Brushes.Solid(color),
     null,
     point
     );
コード例 #16
0
        public void RectangleFloatAndAntialias()
        {
            var imageSize    = new Rectangle(0, 0, 500, 500);
            var floatRect    = new RectangleF(10.5f, 10.5f, 400.6f, 400.9f);
            var expectedRect = new Rectangle(10, 10, 400, 400);
            var path         = new RectangularPolygon(floatRect);
            var processor    = new FillPathProcessor(new ImageSharp.Drawing.Processing.ShapeGraphicsOptions()
            {
                GraphicsOptions =
                {
                    Antialias = true
                }
            }, Brushes.Solid(Color.Red), path);
            var pixelProcessor = processor.CreatePixelSpecificProcessor <Rgba32>(null, null, imageSize);

            Assert.IsType <FillRegionProcessor <Rgba32> >(pixelProcessor);
        }
コード例 #17
0
        public async Task <byte[]> ProcessImage(ImageMeme meme, params string[] replacements)
        {
            var imagebytes = await(await imageStore.GetImageAsync(meme.Template.ImageBaseIdentifier)).GetBytes();

            using var image = Image.Load(imagebytes);
            foreach (var text in meme.Template.memeText)
            {
                // The options are optional

                TextOptions options = new TextOptions()
                {
                    ApplyKerning = true,
                    TabWidth     = 8, // a tab renders as 8 spaces wide
                    //WrapTextWidth = 100, // greater than zero so we will word wrap at 100 pixels wide
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center
                };
                IBrush brush = Brushes.Solid(Color.Parse(text.FillColor));
                IPen   pen   = Pens.Solid(Color.Parse(text.OutlineColor), 2);
                //string text = "sample text";
                string words = text.GetMemeText(random, replacements);
                // draws a star with Horizontal red and blue hatching with a dash dot pattern outline.
                Font f = await getFont(text, words);

                await Task.Run(
                    () => image.Mutate(
                        x => x.DrawText(
                            new DrawingOptions()
                {
                    TextOptions = options
                },
                            words,
                            f,
                            brush,
                            pen, findCenter(text)
                            )
                        )
                    );
            }
            using (var ms = new MemoryStream())
            {
                image.Save(ms, new PngEncoder());
                return(ms.ToArray());
            }
        }
コード例 #18
0
        /// <summary>
        /// Generate image with code
        /// </summary>
        /// <param name="code">Code</param>
        /// <returns></returns>
        private Stream Generate(string code)
        {
            using Image <Rgba32> image = new Image <Rgba32>(null, 200, 80, Rgba32.DarkBlue);
            image.Mutate(x => x.ApplyProcessor(
                             new DrawTextProcessor(
                                 options,
                                 code,
                                 font,
                                 Brushes.Solid(Rgba32.LightBlue),
                                 null,
                                 location)));

            Stream stream = new MemoryStream();

            image.Save(stream, new PngEncoder());
            stream.Seek(0, SeekOrigin.Begin);
            return(stream);
        }
コード例 #19
0
        public void IntRectangle()
        {
            var imageSize    = new Rectangle(0, 0, 500, 500);
            var expectedRect = new Rectangle(10, 10, 400, 400);
            var path         = new RectangularPolygon(expectedRect);
            var processor    = new FillPathProcessor(new ImageSharp.Drawing.Processing.ShapeGraphicsOptions()
            {
                GraphicsOptions =
                {
                    Antialias = true
                }
            }, Brushes.Solid(Color.Red), path);
            var pixelProcessor = processor.CreatePixelSpecificProcessor <Rgba32>(null, null, imageSize);

            var fill = Assert.IsType <FillProcessor <Rgba32> >(pixelProcessor);

            Assert.Equal(expectedRect, fill.GetProtectedValue <Rectangle>("SourceRectangle"));
        }
コード例 #20
0
ファイル: DrawText.Path.cs プロジェクト: woutware/ImageSharp
        public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSet()
        {
            this.operations.DrawText(
                new TextGraphicsOptions(true),
                "123",
                this.Font,
                Brushes.Solid(Rgba32.Red),
                Pens.Dash(Rgba32.Red, 1),
                this.path);

            var processor = this.Verify <FillRegionProcessor <Rgba32> >(0);

            this.Verify <FillRegionProcessor <Rgba32> >(1);
            this.Verify <FillRegionProcessor <Rgba32> >(2);
            this.Verify <FillRegionProcessor <Rgba32> >(3);
            this.Verify <FillRegionProcessor <Rgba32> >(4);
            this.Verify <FillRegionProcessor <Rgba32> >(5);
        }
コード例 #21
0
        static void Main(string[] args)
        {
            using (Image img = new Image(1500, 500))
            {
                var    curve = new Path(new BezierLineSegment(new Vector2(50, 450), new Vector2(200, 50), new Vector2(300, 50), new Vector2(450, 450))).Translate(new Vector2(500, 0));
                var    font  = new Font(FontCollection.SystemFonts.Find("Arial"), 39, FontStyle.Regular);
                string text  = "Hello World";
                text = string.Join(" ", Enumerable.Repeat(text, 5));
                img.Fill(Color.White);
                img.Fill(Color.Gray, curve.GenerateOutline(3));
                img.DrawTextAlongPath(text, font, Brushes.Solid(Color.Black), curve, new ImageSharp.Drawing.TextGraphicsOptions(true)
                {
                    WrapTextWidth = curve.Length
                });

                img.Save("curve.png");
            }
        }
コード例 #22
0
        public void FloatRectAntialiasingOff()
        {
            var imageSize    = new Rectangle(0, 0, 500, 500);
            var floatRect    = new RectangleF(10.5f, 10.5f, 400.6f, 400.9f);
            var expectedRect = new Rectangle(10, 10, 400, 400);
            var path         = new RectangularPolygon(floatRect);
            var processor    = new FillPathProcessor(
                new ShapeGraphicsOptions()
            {
                GraphicsOptions = { Antialias = false }
            },
                Brushes.Solid(Color.Red),
                path);

            IImageProcessor <Rgba32> pixelProcessor = processor.CreatePixelSpecificProcessor <Rgba32>(null, null, imageSize);
            FillProcessor <Rgba32>   fill           = Assert.IsType <FillProcessor <Rgba32> >(pixelProcessor);

            Assert.Equal(expectedRect, fill.GetProtectedValue <Rectangle>("SourceRectangle"));
        }
コード例 #23
0
        public Image <Argb32> Draw()
        {
            var canvas = new Image <Argb32>(Constants.PanelWidth, Constants.PanelHeight);

            canvas.Mutate(x => x.Fill(Brushes.Solid(new Argb32(0, 0, 0, 0))));
            if (this.backgroundImage == null)
            {
                return(canvas);
            }

            canvas.Mutate(x => x.DrawImage(this.backgroundImage.Item, new Point(0, 0), PixelColorBlendingMode.Normal, 1));
            canvas.Mutate(x => x.DrawImage(this.clock.Render(DateTime.Now), new Point(this.clock.X, this.clock.Y), PixelColorBlendingMode.Normal, 1));
            canvas.Mutate(x => x.DrawImage(this.date.Render(DateTime.Now), new Point(this.date.X, this.date.Y), PixelColorBlendingMode.Normal, 1));
            canvas.Mutate(x => x.DrawImage(this.dow.Render(DateTime.Now), new Point(this.dow.X, this.dow.Y), PixelColorBlendingMode.Normal, 1));
            canvas.Mutate(x => x.DrawImage(this.alarm.Render(true), new Point(this.alarm.X, this.alarm.Y), PixelColorBlendingMode.Normal, 1));
            canvas.Mutate(x => x.DrawImage(this.locked.Render(true), new Point(this.locked.X, this.locked.Y), PixelColorBlendingMode.Normal, 1));
            canvas.Mutate(x => x.DrawImage(this.noBluetooth.Render(true), new Point(this.noBluetooth.X, this.noBluetooth.Y), PixelColorBlendingMode.Normal, 1));

            return(canvas);
        }
コード例 #24
0
        // This will do something clever with an image library to generate an image that shows the difference
        private byte[] BuildDifferenceImage(byte[] benchmarkBits, byte[] testBits)
        {
            using (var benchmarkImage = Image.Load(benchmarkBits))
                using (var testImage = Image.Load(testBits))
                    using (var mask = new Image <Rgba32>(null, Math.Min(benchmarkImage.Width, testImage.Width), Math.Min(benchmarkImage.Height, testImage.Height)))
                        using (var redLayer = new Image <Rgba32>(null, Math.Min(benchmarkImage.Width, testImage.Width), Math.Min(benchmarkImage.Height, testImage.Height)))
                        {
                            redLayer.Mutate(i => i.FillPolygon(Brushes.Solid(new Rgba32(255, 255, 255, 0)), new PointF(0, 0), new PointF(mask.Width, 0), new PointF(mask.Width, mask.Height), new PointF(0, mask.Height)));
                            mask.Mutate(i => i.FillPolygon(Brushes.Solid(new Rgba32(255, 255, 255, 120)), new PointF(0, 0), new PointF(mask.Width, 0), new PointF(mask.Width, mask.Height), new PointF(0, mask.Height)));

                            var opaque = Brushes.Solid(new Rgba32(255, 255, 255, 0));
                            var red    = Brushes.Solid(new Rgba32(255, 0, 0, 255));

                            var maskOptions = new GraphicsOptions {
                                BlenderMode = PixelBlenderMode.Src
                            };
                            var diffImageOptions = new GraphicsOptions {
                                BlenderMode = PixelBlenderMode.Darken
                            };

                            for (int y = 0; y < mask.Height; y++)
                            {
                                for (int x = 0; x < mask.Width; x++)
                                {
                                    if (benchmarkImage[x, y] != testImage[x, y])
                                    {
                                        var rect = new [] { new PointF(x - HIGHLIGHT_SIZE / 2, y - HIGHLIGHT_SIZE / 2), new PointF(x + HIGHLIGHT_SIZE / 2, y - HIGHLIGHT_SIZE / 2), new PointF(x + HIGHLIGHT_SIZE / 2, y + HIGHLIGHT_SIZE / 2), new PointF(x - HIGHLIGHT_SIZE / 2, y + HIGHLIGHT_SIZE / 2) };
                                        mask.Mutate(i => i.FillPolygon(maskOptions, opaque, rect));
                                        redLayer.Mutate(i => i.FillPolygon(diffImageOptions, red, rect));

                                        x += HIGHLIGHT_SIZE;
                                    }
                                }
                            }

                            testImage.Mutate(i => i.DrawImage(redLayer, PixelBlenderMode.Darken, 0.20f).DrawImage(mask, 1f));

                            return(SaveImage(testImage));
                        }
        }
コード例 #25
0
        // Create a single "overlay" image.
        async Task CreateOverlayAsync(string inputPath, string outputPath, Image fadedImage, float fadeRatio)
        {
            IBrush backgroundbrush = Brushes.Solid(Color.FromRgba(0, 0, 0, 224));
            IPen   backgroundpen   = Pens.Solid(Color.Blue, 1);

            // Creates a new image with empty pixel data.
            using (var image = await Image.LoadAsync(inputPath))
            {
                Rectangle rectangle = new Rectangle(4, 5, 139, 20);

                image.Mutate(x => x.Fill(backgroundbrush, rectangle)
                             .Draw(backgroundpen, rectangle)
                             );

                // You should find a better way to get the timestamp :)
                string text = ImageTimeStamp.ToString("yyyy-MM-dd HH:mm");
                ImageTimeStamp = ImageTimeStamp.AddMinutes(1);

                Color fontColor   = Color.White;
                Font  OverlayFont = MyFontFamily.CreateFont(14, FontStyle.Regular);
                TextGraphicsOptions textoptions = new TextGraphicsOptions()
                {
                    GraphicsOptions = new GraphicsOptions()
                    {
                        Antialias = true
                    }
                };

                // Draw the text
                image.Mutate(x => x.DrawText(textoptions, text, OverlayFont, fontColor, new PointF(8, 7)));

                // Fade in the other image
                if (fadedImage != null && fadeRatio > 0)
                {
                    image.Mutate(x => x.DrawImage(fadedImage, fadeRatio));
                }

                await image.SaveAsPngAsync(outputPath).ConfigureAwait(false);
            }
        }
コード例 #26
0
        /// <summary>
        /// Add a password to the image.
        /// </summary>
        /// <param name="curImg">Image to add password to.</param>
        /// <param name="pass">Password to add to top left corner.</param>
        /// <returns>Image with the password in the top left corner.</returns>
        private (Stream, string) AddPassword(byte[] curImg, string pass)
        {
            // draw lower, it looks better
            pass = pass.TrimTo(10, true).ToLowerInvariant();
            using (var img = Image.Load(curImg, out var format))
            {
                // choose font size based on the image height, so that it's visible
                var font = _fonts.NotoSans.CreateFont(img.Height / 10, FontStyle.Bold);
                img.Mutate(x =>
                {
                    // measure the size of the text to be drawing
                    var size = TextMeasurer.Measure(pass, new RendererOptions(font, new PointF(0, 0)));

                    // fill the background with black, add 5 pixels on each side to make it look better
                    x.FillPolygon(Rgba32.FromHex("00000080"),
                                  new PointF(0, 0),
                                  new PointF(size.Width + 5, 0),
                                  new PointF(size.Width + 5, size.Height + 10),
                                  new PointF(0, size.Height + 10));

                    Random random = new Random();

                    x.DrawLines(Brushes.Solid(Rgba32.White), 2,
                                new PointF(0, (float)random.NextDouble() * size.Height),
                                new PointF(size.Width + 5, (float)random.NextDouble() * size.Height));

                    x.DrawLines(Brushes.Solid(Rgba32.White), 2,
                                new PointF(0, (float)random.NextDouble() * size.Height),
                                new PointF(size.Width + 5, (float)random.NextDouble() * size.Height));

                    // draw the password over the background
                    x.DrawText(pass,
                               font,
                               Brushes.Solid(Rgba32.White),
                               new PointF(0, 0));
                });
                // return image as a stream for easy sending
                return(img.ToStream(format), format.FileExtensions.FirstOrDefault() ?? "png");
            }
        }
コード例 #27
0
ファイル: MemeLoader.cs プロジェクト: wchill/Rem
        public static MemeTemplate LoadKomiMemeTemplate()
        {
            var imageRenderer = GetDefaultImageInputRenderer();

            var font         = MemeFonts.GetFont(AvailableFonts.AnimeAce);
            var textRenderer = new TextInputRenderer(font, null, Brushes.Solid(Rgba32.Black), HorizontalAlignment.Left, VerticalAlignment.Top, false);

            var inputField = new InputFieldBuilder()
                             .WithName("Paper", "Whatever Komi's looking at on the paper")
                             .WithVertices(new Point(245, 479), new Point(707, 563), new Point(48, 980), new Point(557, 1067))
                             .WithRenderer(imageRenderer)
                             .WithRenderer(textRenderer)
                             .WithPadding(0.03)
                             .WithMask(new Point(245, 479), new Point(665, 556), new Point(665, 699), new Point(555, 1066), new Point(184, 1068), new Point(184, 633))
                             .Build();

            return(new MemeTemplateBuilder("Images/MemeTemplates/KomiPaper.png")
                   .WithName("Komi")
                   .WithDescription("Komi-san reads something and gets excited!")
                   .WithInputField(inputField)
                   .Build());
        }
コード例 #28
0
ファイル: SpoilersService.cs プロジェクト: Slamerz/DmC
 public Task <MagickImageCollection> SpoilerImg(string uri) => Task.Run(async() =>
 {
     //load image
     var img2 = await DownloadImageAsync(uri);
     //create spoiler warning image
     Image <Rgba32> img1 = new Image <Rgba32>(img2.Width, img2.Height);
     _Spoil    = _fonts.Find("Whitney-Bold").CreateFont(img2.Width * 0.064f);
     var fill  = Brushes.Solid <Rgba32>(Rgba32.Black);
     var brush = Brushes.Solid <Rgba32>(Rgba32.White);
     var rect  = new Rectangle(0, 0, img2.Width, img2.Height);
     img1.BackgroundColor(Rgba32.Black, rect);
     img1.DrawText("Spoiler Warning" + "\r\n" + "(Mouse over to view)", _Spoil, brush, new PointF(10, 10), new TextGraphicsOptions(true)
     {
         WrapTextWidth = img1.Width - 20
     });
     MagickImage f1       = new MagickImage(img1.ToStream());
     MagickImage f2       = new MagickImage(img2.ToStream());
     MagickImage[] frames = { f1, f2 };
     var gifs             = GetGif(frames);
     var gif = new MagickImageCollection(gifs);
     return(gif);
 });
コード例 #29
0
        public void DrawForEachACharacterWhenPenSetAndFillFroEachWhenBrushSet()
        {
            this.operations.DrawText(
                new TextGraphicsOptions(true),
                "123",
                this.Font,
                Brushes.Solid(Color.Red),
                Pens.Dash(Color.Red, 1),
                Vector2.Zero);

            var processor = this.Verify <DrawTextProcessor>(0);

            Assert.Equal("123", processor.Text);
            Assert.Equal(this.Font, processor.Font);
            var brush = Assert.IsType <SolidBrush>(processor.Brush);

            Assert.Equal(Color.Red, brush.Color);
            Assert.Equal(PointF.Empty, processor.Location);
            var penBrush = Assert.IsType <SolidBrush>(processor.Pen.StrokeFill);

            Assert.Equal(Color.Red, penBrush.Color);
            Assert.Equal(1, processor.Pen.StrokeWidth);
        }
コード例 #30
0
        public static async Task <string> Draw(CharacterInfo character)
        {
            if (character.Portrait == null)
            {
                throw new Exception("Character has no portrait");
            }

            string portraitPath = PathUtils.Current + "/Temp/" + character.Id + ".jpg";
            await FileDownloader.Download(character.Portrait, portraitPath);

            Image <Rgba32> charImg = Image.Load <Rgba32>(portraitPath);

            Image <Rgba32> backgroundImg = Image.Load <Rgba32>(PathUtils.Current + "/Assets/CharacterPortraitBackground.png");

            backgroundImg.Mutate(x => x.Resize(charImg.Width, charImg.Height));

            Image <Rgba32> finalImg = new Image <Rgba32>(charImg.Width, charImg.Height);

            finalImg.Mutate(x => x.DrawImage(backgroundImg, 1.0f));
            finalImg.Mutate(x => x.DrawImage(charImg, 1.0f));

            PointF boxA = new PointF(5, charImg.Height - 120);
            PointF boxB = new PointF(finalImg.Width - 5, charImg.Height - 120);
            PointF boxC = new PointF(finalImg.Width - 5, charImg.Height - 5);
            PointF boxD = new PointF(5, charImg.Height - 5);

            finalImg.Mutate(x => x.FillPolygon(Brushes.Solid(Color.Black.WithAlpha(0.4F)), boxA, boxB, boxC, boxD));
            finalImg.Mutate(x => x.DrawText(FontStyles.CenterText, character.Server + " - " + character.DataCenter, Fonts.AxisRegular.CreateFont(26), Color.White, new Point(finalImg.Width / 2, charImg.Height - 95)));
            finalImg.Mutate(x => x.DrawTextAnySize(FontStyles.CenterText, character.Name, Fonts.OptimuSemiBold, Color.White, new Rectangle(finalImg.Width / 2, finalImg.Height - 50, 600, 70)));

            // Save
            string outputPath = PathUtils.Current + "/Temp/" + character.Id + "_render.png";

            finalImg.Save(outputPath);

            return(outputPath);
        }