画线是否正确?

时间:2018-12-04 11:47:03

标签: .net vb.net graphics

在以下代码中,绘制线条功能无法正常使用。但是当使用画线绘制相同的数据时,它可以正常工作。画线画的线不是真实的。您对此有何评论?

   Dim uImage As Bitmap = New Bitmap(PictureBox1.Size.Width, PictureBox1.Size.Height, 4, Imaging.PixelFormat.Format32bppPArgb, 0)

   Dim Grafik As Graphics = Graphics.FromImage(uImage)

   Grafik.Clear(Color.Black)

   Dim Offset As Integer = 0
   Dim Gain As Integer = 1
   Dim Freq As Integer = 1
   Dim N As Integer = PictureBox1.Size.Width

   Dim D(N - 1) as PointF

    ' Create Data
    '
    For i As Integer = 0 To N - 1
        D(i).X = i
        D(i).Y = Offset + Gain * Math.Cos(i * Freq * Math.PI / 180.0)
    Next

   ' Scale for drawing
   '
   Dim sx As Double = PictureBox1.Size.Width / (N - 1)
   Dim sy As Double = PictureBox1.Size.Height * 0.5

   ' increase gain
   '
   sy=sy*32000

   ' Data to Pixel
   '
   For i As Integer = 0 To N - 1
       D(i).X = D(i).X * sx
       D(i).Y = PictureBox1.Size.Height * 0.5 - D(i).Y * sy
   Next

    ' DrawLines is not correct
    '
    Grafik.DrawLines(New Pen(Color.Blue), D)

   ' DrawLine is correct
   '
    For i As Integer = 1 To N - 1
        Grafik.DrawLine(New Pen(Color.Red), D(i - 1), D(i))
    Next

    PictureBox1.Image = Nothing
    PictureBox1.Image = uImage

    Grafik.Dispose()

我想提供更多信息。当Picturebox达到特定尺寸时,可能会发生错误。此示例的尺寸为720; 530像素。正在获取以下图像:

Image showing vertical lines

图像中不应出现蓝线。应该与红线重叠。

0 个答案:

没有答案