mono / libgdiplus

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

DrawImage with WrapMode.TileFlipXY sometimes renders outside destination rectangle. #731

Open jhergens opened 2 years ago

jhergens commented 2 years ago

When drawing images with image attributes having wrap mode set to WrapMode.TileFlipXY, the image is sometimes repeated outside the destination rectangle. Seems a bit random when this happens and if it is repeated for X, Y or both.

The below code:

using var backBuffer = new Bitmap(973, 560);
using (var graphics = Graphics.FromImage(backBuffer))
{
    graphics.Clear(Color.White);
    using var testImage = new Bitmap(1570, 1377);
    using (var graphics2 = Graphics.FromImage(testImage))
    {
        graphics2.Clear(Color.Red);
        using var pen = new Pen(Color.Black, 10);
        graphics2.DrawLine(pen, 0, 0, testImage.Width, testImage.Height);
        graphics2.DrawRectangle(pen, 0, 0, testImage.Width, testImage.Height);
    }

    var destRect = new Rectangle(192, 49, 486, 360);
    var imageAttributes = new ImageAttributes();
    imageAttributes.SetWrapMode(WrapMode.TileFlipXY);
    graphics.DrawImage(testImage, destRect, 0, 0, testImage.Width, testImage.Height, GraphicsUnit.Pixel, imageAttributes);
}

Results in this image:

flip_linux

Expected it to like like this (Windows): flip_win

We are building libgdiplus from main.