Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

GdipDrawImagePointsRect does not handle Graphics with a transformation. #728

Open
jhergens opened this issue Dec 6, 2021 · 0 comments
Open

Comments

@jhergens
Copy link

jhergens commented Dec 6, 2021

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant