I've got a Bitmap object that i need to draw onto another bitmap in a user chosen location and size. Currently the image being drawn using the Graphics.DrawImage() method preserves the aspect ratio as far as i can tell.
How can i draw the image stretched to fill the target area?
You should transform the coordinate system to draw the image stretched.
Here is an example:
using Aurigma.GraphicsMill;
using System;
class Program
{
static void Main(string[] args)
{
int x = 70;
int y = 90;
float width = 250f;
float height = 100f;
using (var bitmap = new Bitmap(400, 300, PixelFormat.Format24bppRgb, RgbColor.White))
using (var top = new Bitmap("../../../input.jpg"))
using (var graphics = bitmap.GetAdvancedGraphics())
{
var transform = new System.Drawing.Drawing2D.Matrix();
transform.Translate(x, y);
transform.Scale(width / (float)(top.Width), height / (float)(top.Height));
graphics.Transform = transform;
graphics.DrawImage(top, 0, 0);
bitmap.Save("../../../sample.jpg");
}
}
}