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;
}