The SmoothingMode should definitely impact your output
Here's some settings I recently used for resizing an image with minimal quality loss:
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
The InterpolationMode is probably not relevant for your example but the PixelOffsetMode might be. Let me spin up a quick test app.
Update: Here's the quick test app, SmoothingMode definitely impacts the lines I draw.
private void Form1_Load(object sender, EventArgs e)
{
foreach (var value in Enum.GetValues(typeof(SmoothingMode)))
{
_ComboBoxSmoothingMode.Items.Add(value);
}
foreach (var value in Enum.GetValues(typeof(PixelOffsetMode)))
{
_ComboBoxPixelOffsetMode.Items.Add(value);
}
_ComboBoxPixelOffsetMode.SelectedIndex = 0;
_ComboBoxSmoothingMode.SelectedIndex = 0;
}
private void _ButtonDraw_Click(object sender, EventArgs e)
{
using (Graphics g = _LabelDrawing.CreateGraphics())
{
g.Clear(Color.White);
if (_ComboBoxPixelOffsetMode.SelectedItem != null && (PixelOffsetMode)_ComboBoxPixelOffsetMode.SelectedItem != PixelOffsetMode.Invalid)
{
g.PixelOffsetMode = (PixelOffsetMode)_ComboBoxPixelOffsetMode.SelectedItem;
}
if (_ComboBoxSmoothingMode.SelectedItem != null && (SmoothingMode)_ComboBoxSmoothingMode.SelectedItem != SmoothingMode.Invalid)
{
g.SmoothingMode = (SmoothingMode)_ComboBoxSmoothingMode.SelectedItem;
}
using (Pen pen = new Pen(Color.Blue, 3))
{
g.DrawLines(pen, new[] { new Point(0, 0), new Point(25, 50), new Point(_LabelDrawing.Width - 25, _LabelDrawing.Height - 50), new Point(_LabelDrawing.Width, _LabelDrawing.Height), });
}
}
}
SmoothingMode: AntiAlias None
Update: As Morbo pointed out if the Graphics
object presented to you in the PaintEventArgs
isn't the same Graphics
object that will ultimately be used for display then changing the smoothing might not have any effect. Although I would not expect such a drastic difference if that was a Graphics
object from a memory Image
or something.
Wish I could offer more. Maybe if I understood better what the LineShape
was giving you and your reasoning for using it over just using one of the Graphics.DrawLine() methods.
The reason I question your use of the LineShape
is that you are overriding it's OnPaint and drawing your own line. Seems like you could simplify your application and ditch the LineShape
but maybe I'm missing something.
Update: Ok that makes sense why you are using the LineShape
then. Only suggestion I can offer at this point is to override OnPaint in your panel or LineShape, try setting the smoothing mode there before calling the base event. Something like:
protected override void OnPaint(PaintEventArgs e)
{
e.Graphichs.SmoothingMode = SmoothingMode.AntiAlias;
base.OnPaint(e);
}