mono / libgdiplus

C-based implementation of the GDI+ API
http://www.mono-project.com/
MIT License
333 stars 171 forks source link

GdipDrawImagePointsRect does not handle Graphics with a transformation. #728

Open jhergens opened 2 years ago

jhergens commented 2 years ago

GdipDrawImagePointsRect does not take any existing transformation in the graphics object into account.

The following code:

var bitmap = new Bitmap(1000, 1000);
using (var graphics = Graphics.FromImage(bitmap))
{
    graphics.ScaleTransform(10, 10);
    graphics.Clear(Color.White);

    var redBitmap = new Bitmap(50, 50);
    using (var redGraphics = Graphics.FromImage(redBitmap))
    {
        redGraphics.Clear(Color.Red);
    }

    var destRect = new RectangleF(25, 25, 50, 50);
    var srcRect = new RectangleF(0, 0, 50, 50);

    PointF[] destRectanglePoints =
    {
        new(destRect.Left, destRect.Top),
        new(destRect.Right, destRect.Top),
        new(destRect.Left, destRect.Bottom)
    };

    // This one is broken.
    graphics.DrawImage(redBitmap, destRectanglePoints, srcRect, GraphicsUnit.Pixel);

    // This one works
    // graphics.DrawImage(redBitmap, destRect, srcRect, GraphicsUnit.Pixel);

    using (var pen = new Pen(Color.Black))
    {
        graphics.DrawRectangle(pen, new Rectangle(25, 25, 50, 50));
    }
}

Renders like this: screenshot-3

It is expected to render like this: screenshot-4

We are building libgdiplus from main.