'How to center a super imposed bitmap properly?

I generate a QR code from code, then superimpose it over another image. Thie issue is that it doesn't line up as I expected.

/// <summary>
/// Draw one bitmap over another.
/// </summary>
/// <param name="largeBmp"></param>
/// <param name="smallBmp"></param>
/// <returns></returns>
public Bitmap Superimpose(Bitmap largeBmp, Bitmap smallBmp) {

    Graphics g = Graphics.FromImage(largeBmp);
    g.CompositingMode = CompositingMode.SourceOver;
    
    // Resize it so it fists
    smallBmp = ResizeBitmap(smallBmp, smallBmp.Width / 4, smallBmp.Height / 4);

    var x = (largeBmp.Width -  smallBmp.Width) / 2;
    var y = (largeBmp.Height - smallBmp.Height)/ 2;

    g.DrawImage(smallBmp, new Point(x, y));

    return largeBmp;
}

/// <summary>
/// Resize the bitmap
/// </summary>
/// <param name="bmp"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <returns></returns>
public Bitmap ResizeBitmap(Bitmap bmp, int width, int height)
{
    Bitmap result = new Bitmap(width, height);
    using (Graphics g = Graphics.FromImage(result))
    {
        g.DrawImage(bmp, 0, 0, width, height);
    }

    return result;
}

Non-Aligned Image



Solution 1:[1]

I tried your code in win forms project and code worked fine, I used png format for large and small images, I think you should check your QR code, it might have some blank space around it

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Surinder Singh