Rank: Advanced Member
Groups: Guest
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: When DPIs are different Graphics.DrawImage output Image when the dpis are different: Bitmap.Draw output when dpis are different: When DPIs are the same: Graphics.DrawImage output Image when the dpis are the same: Bitmap.Draw output when dpis are the same: 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");
}
|