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

Can't draw images that are scaled in one direction only #729

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

Can't draw images that are scaled in one direction only #729

jhergens opened this issue Dec 6, 2021 · 0 comments

Comments

@jhergens
Copy link

jhergens commented Dec 6, 2021

When rendering an image where either the width or height of the source and destination rectangles are the same, no scaling will occur even if the rectangles differ in the other dimension.

The following code:

var bitmap = new Bitmap(100, 200);
using (var graphics = Graphics.FromImage(bitmap))
{
    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, 150);
    var srcRect = new RectangleF(0, 0, 50, 50);
 
    graphics.DrawImage(redBitmap, destRect, srcRect, GraphicsUnit.Pixel);
 
    using (var pen = new Pen(Color.Black))
    {
        graphics.DrawRectangle(pen, Rectangle.Round(destRect));
    }
}

Renders like this:
image-1

It is expected to render like this:
image-2

We are building libgdiplus from main.

It seems the problem is the following snippet in GdipDrawImageRectRect

if (!gdip_near_zero(srcwidth - dstwidth) && !gdip_near_zero(srcheight - dstheight))
  cairo_matrix_scale (&mat, srcwidth / dstwidth, srcheight / dstheight);

Changing && to || fixes this.

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