gpt4 book ai didi

.net - GDI+ 如何更改线条平滑模式?

转载 作者:行者123 更新时间:2023-12-04 14:36:27 24 4
gpt4 key购买 nike

可以改吗PowerPacks.LineShape平滑模式?

我尝试使用此代码(继承 LineShape 的类):

  Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim g As Graphics = e.Graphics

' no difference when changing the SmoothingMode '
g.SmoothingMode = SmoothingMode.AntiAlias

Using pen As New Pen(Color.Blue, 3)
g.DrawLine(pen, X1, Y1, X2, Y2)
End Using

' MyBase.OnPaint(e) '
End Sub

我总是有相同的结果,就像这样:
alt text http://lh6.ggpht.com/_1TPOP7DzY1E/S3v1IbxlbCI/AAAAAAAADD4/q1Y9kP8wJ0g/s800/Capture2.png

========

编辑

更新了测试:
  Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim g As Graphics = e.Graphics

Dim oldmode As SmoothingMode = g.SmoothingMode

Using pen As New Pen(Color.Blue, 3)
g.SmoothingMode = SmoothingMode.AntiAlias
g.DrawLine(pen, X1, Y1, X2, Y2)
g.SmoothingMode = SmoothingMode.None
g.DrawLine(pen, X1 + 50, Y1, X2 + 50, Y2)
End Using

g.SmoothingMode = oldmode
g.Flush()

'MyBase.OnPaint(e)'
End Sub

结果 (不考虑标签和圆圈):

alt text http://lh3.ggpht.com/_1TPOP7DzY1E/S447qYvTqzI/AAAAAAAADE8/eP3kCLqQJbk/s800/Capture2.png

显然没有考虑平滑模式......

最佳答案

SmoothingMode 肯定会影响您的输出

以下是我最近用于以最小质量损失调整图像大小的一些设置:

graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

InterpolationMode 可能与您的示例无关,但 PixelOffsetMode 可能是。让我启动一个快速测试应用程序。

更新:这是快速测试应用程序,SmoothingMode 肯定会影响我绘制的线条。
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

SmoothingMode.AntiAlias http://www.ccswe.com/temp/SmoothingMode_AntiAlias.pngSmoothingMode.None http://www.ccswe.com/temp/SmoothingMode_None.png

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);
}

关于.net - GDI+ 如何更改线条平滑模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2280576/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com