Welcome Guest! You need to login or register to make posts.



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: Member
Joined: 6/9/2016(UTC)
Posts: 30

Thanks: 20 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?

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

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,556

Thanks: 5 times
Was thanked: 62 time(s) in 61 post(s)
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);

Fedor attached the following image(s):
Best regards,
Fedor Skvortsov
thanks 1 user thanked Fedor for this useful post.
Chris Jones on 6/21/2016(UTC)
Users browsing this topic
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.