Rank: Advanced Member
Groups: Guest
Joined: 6/9/2016(UTC) Posts: 34
Thanks: 22 times
|
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? Thanks
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 7/28/2003(UTC) Posts: 1,660
Thanks: 5 times Was thanked: 76 time(s) in 74 post(s)
|
You should transform the coordinate system to draw the image stretched. Here is an example: Code: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");
}
}
}
Fedor attached the following image(s): |
Best regards, Fedor Skvortsov
|
1 user thanked Fedor for this useful post.
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.