runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Linux version of GraphicsPath.Warp wipes the path and results in an empty bitmap.

Open baal2000 opened this issue 8 years ago • 2 comments

SDK: netcoreapp2.1

Repro results:

Repro: here

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

namespace GenerateBitmapTest
{
    class Program
    {
        static void Main()
        {
            var bmap = GenerateBitmap("TEST");
            bmap.Save("image.jpg");
        }

        static Bitmap GenerateBitmap(string text)
        {
            const int Width = 300;
            const int Height = 75;
            var bitmap = new Bitmap(Width, Height, PixelFormat.Format32bppArgb);
            using (var graphics = Graphics.FromImage(bitmap))
            {
                graphics.SmoothingMode = SmoothingMode.AntiAlias;
                var rectangle = new Rectangle(0, 0, Width, Height);
                SizeF size;
                float fontSize = rectangle.Height + 1;
                Font font;
                do
                {
                    fontSize--;
                    font = new Font(FontFamily.GenericSansSerif, fontSize, FontStyle.Bold);
                    size = graphics.MeasureString(text, font);
                }
                while (size.Width > rectangle.Width);
                var format = new StringFormat
                {
                    Alignment = StringAlignment.Center,
                    LineAlignment = StringAlignment.Center
                };
                using (var path = new GraphicsPath())
                {
                    using (font)
                    {
                        path.AddString(text, font.FontFamily, (int)font.Style, font.Size, rectangle, format);
                    }
                    const float V = 4F;
                    var random = new Random(DateTime.UtcNow.Millisecond);
                    PointF[] points =
                    {
                        new PointF(random.Next(rectangle.Width) / V, random.Next(rectangle.Height) / V),
                        new PointF(rectangle.Width - random.Next(rectangle.Width) / V, random.Next(rectangle.Height) / V),
                        new PointF(random.Next(rectangle.Width) / V, rectangle.Height - random.Next(rectangle.Height) / V),
                        new PointF(rectangle.Width - random.Next(rectangle.Width) / V, rectangle.Height - random.Next(rectangle.Height) / V)
                    };
                    path.Warp(points, rectangle, null, WarpMode.Perspective, 0F);
                    using (var brush = new SolidBrush(Color.Black))
                    {
                        graphics.FillPath(brush, path);
                    }
                }
            }
            return bitmap;
        }
    }
}

baal2000 avatar Nov 15 '18 20:11 baal2000

How to resolve this issue?

SeriaWei avatar Jan 01 '21 01:01 SeriaWei

Closing this issue as System.Drawing.Common is only supported on Windows now.

JeremyKuhne avatar Mar 14 '23 20:03 JeremyKuhne