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

Notification

Icon
Error

Options
Go to last post Go to first unread
Todd Kneib  
#1 Posted : Tuesday, July 9, 2019 12:29:15 PM(UTC)
Todd Kneib

Rank: Advanced Member

Groups: Member
Joined: 5/10/2006(UTC)
Posts: 32

Thanks: 6 times
Using version 9.3.37.0, if I use DrawImage on AdvancedDrawing.Graphics to drawn an image that is a different DPI than the dpi of the graphics object, DrawImage does not resize the image being drawn like the description says it should. If the image being drawn has the same DPI as the graphics object, then DrawImage DOES resize.
Original Image: orgImg.png
When DPIs are different
Graphics.DrawImage output Image when the dpis are different: outputBmp_DiffDPI.png
Bitmap.Draw output when dpis are different: directOutBmp_DiffDPI.png

When DPIs are the same:
Graphics.DrawImage output Image when the dpis are the same: outputBmp_SameDPI.png
Bitmap.Draw output when dpis are the same: directOutBmp_SameDPI.png

Should Graphics.DrawImage be resizing to FIT (as it is) or should it be stretching the image to fit like Bitmap.Draw does? Should Bitmap.Draw be stretching to fit?


Code to reproduce:

Code:

//using Aurigma.GraphicsMill
//using Aurigma.GraphicsMill.AdvancedDrawing
//using Aurigma.GraphicsMill.Transforms

void Main()
{
	// Generate Orignal image
	int orgWidth = 800;
	int orgHeight = 400;
	int orgDPI = 150;

	int gutterHeight = 20;
	int outWidth = 400;
	int outHeight = 300;
	int outDPI = 150;

	var orgBitmap = new Bitmap(orgWidth,orgHeight,PixelFormat.Format24bppRgb, RgbColor.LightGreen);
	orgBitmap.DpiX = orgDPI;
	orgBitmap.DpiY = orgDPI;
	using (var g = orgBitmap.GetAdvancedGraphics())
	using (var p = new Pen(RgbColor.Brown, 2f))
	{
		g.DrawRectangle(p, 10, 10, orgWidth - 20, orgHeight - 20);
		g.DrawRectangle(p, 20, 20, 80, 60);
	}
	
	orgBitmap.Save(@"C:\temp\orgImg.png");
	
	// draw the original image onto another bitmap 

	var outputBmp = new  Bitmap(outWidth, outHeight + gutterHeight,PixelFormat.Format24bppRgb, RgbColor.Wheat);
	outputBmp.DpiX = outDPI;
	outputBmp.DpiY = outDPI;
	
	using (var g = outputBmp.GetAdvancedGraphics())
	{
		var drawRect = new System.Drawing.RectangleF(0, 1, outWidth, gutterHeight);
		g.DrawText(
			new BoundedText(
			"Top gutter text",  
			g.CreateFont("Arial", 8), 
			new SolidBrush(RgbColor.Black), 
			drawRect, TextAlignment.Center));
		
		// This will NOT resize the image to fit the destination rectangle 
		// when the orgBitmap's DPI does not match the outputDPI
		g.DrawImage(orgBitmap, new System.Drawing.RectangleF(0, gutterHeight, outWidth, outHeight), 1);
	}
	outputBmp.Save(@"C:\temp\outputBmp.png");
	
	 
	var directOutBmp = new Bitmap(outWidth, outHeight + gutterHeight, PixelFormat.Format24bppRgb, RgbColor.PowderBlue);
	directOutBmp.DpiX = outDPI;
	directOutBmp.DpiY = outDPI;
	// This call WILL resize the orgBitmap to the destination rectangle regardless of if the DPIs match or not
	directOutBmp.Draw(
		orgBitmap, 
		new System.Drawing.Rectangle(0, gutterHeight, outWidth, outHeight), 
		CombineMode.Alpha, 
		1, 
		ResizeInterpolationMode.High);
	directOutBmp.Save(@"C:\temp\directOutBmp.png");
	
}


Eugene Kosmin  
#2 Posted : Wednesday, July 10, 2019 1:34:06 AM(UTC)
Eugene Kosmin

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 9/19/2006(UTC)
Posts: 505

Was thanked: 41 time(s) in 41 post(s)
Hi Todd,

Thanks for the detailed explanation.
Quote:
Should Graphics.DrawImage be resizing to FIT (as it is) or should it be stretching the image to fit like Bitmap.Draw does? Should Bitmap.Draw be stretching to fit?

Graphics.DrawImage should stretch the image to fit the rectangle passed as an argument. I'll post a ticket to our bug tracker regarding this issue.
Best regards,
Eugene Kosmin
The Aurigma Development Team
Todd Kneib  
#3 Posted : Wednesday, July 10, 2019 6:27:28 AM(UTC)
Todd Kneib

Rank: Advanced Member

Groups: Member
Joined: 5/10/2006(UTC)
Posts: 32

Thanks: 6 times
Since we have an active maintenance license for 9.x, will this fix be applied to the 9.x version?
Fedor  
#4 Posted : Thursday, July 11, 2019 12:29:32 AM(UTC)
Fedor

Rank: Advanced Member

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

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
Quote:
Since we have an active maintenance license for 9.x, will this fix be applied to the 9.x version?


We will fix it in the last version 10.x. As your maintenance subscription is active, you are eligible to get a free upgrade. The last version is fully compatible with version 9.

Edited by user Thursday, July 11, 2019 12:30:05 AM(UTC)  | Reason: Not specified

Best regards,
Fedor Skvortsov
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.