【问题标题】:Interpolation anomaly during drawing绘图期间插值异常
【发布时间】:2012-12-18 14:26:14
【问题描述】:

我在使用抗锯齿平滑模式和绘图时遇到问题。 假设我有一个在同一点具有最小值和最大值的信号。 所以我想显示它以查看它“更厚”的位置。

所以我使用的方法是绘制垂直线并使用抗锯齿。 这是问题所在,上升沿似乎是抗锯齿的,但下降沿没有。 如果我在第二个信号中添加了一些噪音,则可以观察到同样的事情。

无噪音

有噪音

![有噪音][2]

谁能指出我错过了什么?或者这个问题来自其他地方?

代码(来自 cmets):

Bitmap drawBitmap = new Bitmap(pictureBox1.Height, _
                               pictureBox1.Width, _
                               System.Drawing.Imaging.PixelFormat.Format32bppArgb);

Graphics drawGraph;

Point[] pts = new Point[] { new Point(0, 60), new Point(0, 59), new Point(1, 35), _
                            new Point(1, 47), new Point(2, 25), new Point(2, 35), _
                            new Point(3, 17), new Point(3, 25), new Point(4, 12), _
                            new Point(4, 27), new Point(5, 10), new Point(5, 22), _
                            new Point(6, 10), new Point(6, 11), new Point(7, 11), _
                            new Point(7, 16), new Point(8, 16), new Point(8, 24), _
                            new Point(9, 24), new Point(9, 34), new Point(10, 34), _
                            new Point(10, 46), new Point(11, 46), new Point(11, 59), _
                            new Point(12, 59), new Point(12, 72)};

using (drawGraph = Graphics.FromImage(drawBitmap)) {

    drawGraph.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic;
    drawGraph.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias; 

for (int i = 1; i < pts.Length - 1; i += 2) {
    drawGraph.DrawLine(new Pen(Color.Black, 1), pts[i], pts[i - 1]); 
    drawGraph.DrawLine(new Pen(Color.Black, 1), pts[i], pts[i + 1]);
    }
} 

pictureBox1.Image = drawBitmap;

【问题讨论】:

  • 您不需要在帖子中包含签名 - 您的用户卡会自动添加。阅读FAQ了解更多详情。
  • 你能告诉我们你用来画这个的代码吗?
  • 如果这是一个愚蠢的问题,我很抱歉,但是在我发现的第一个 Google 结果this page 上,该示例在向下笔划时具有抗锯齿功能,但在向上笔划时故意将其关闭.你没有做类似的事情,是吗?
  • 抗锯齿在代码开始时开启一次。所以这就是为什么我不明白为什么它似乎不使用插值。实际上,如果我画不直的线,它会被很好地插值,但如果我只画垂直线,下降沿及其环境不会抗锯齿。
  • 您能向我们展示您的代码,以便我们尝试复制它吗?

标签: c# drawing interpolation antialiasing smoothing


【解决方案1】:

也应用像素偏移模式:

drawGraph.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality;

InterpolationMode 可以删除,因为它与线条无关(仅在调整大小时适用于图像)。

【讨论】:

  • 没问题。提示:您可以使用 DrawLines() 方法而不是 DrawLine()。这可以将您的点数组一次全部绘制出来。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-08-06
  • 1970-01-01
  • 1970-01-01
  • 2017-01-24
  • 1970-01-01
  • 1970-01-01
  • 2015-07-13
相关资源
最近更新 更多