This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

Notification

Icon
Error

Options
Go to last post Go to first unread
Chris Jones  
#1 Posted : Monday, June 20, 2016 7:25:06 AM(UTC)
Chris Jones

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

Fedor  
#2 Posted : Monday, June 20, 2016 9:52:50 AM(UTC)
Fedor

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):
sample.jpg
Best regards,

Fedor Skvortsov

thanks 1 user thanked Fedor for this useful post.
Chris Jones on 6/21/2016(UTC)
Users browsing this topic
Guest
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.