Visual Basic 中学校 掲示板 投稿内容
タグのない投稿を抽出 統計 RSS

Visual Basic 中学校 > 投稿一覧 >

AddCurveやAddLinesで思ったような図形が描けません

タグの編集...

投稿者 snowmansnow   (社会人)   投稿日時 2022/1/9 23:56:43

 こんばんは
  VB.NETです
   PicturboxにDrawCurveすると思った図形になるのですが、
   FormにAddCurveやAddLinesすると変な図形になってしまいます。
   Flattenしたいので、AddCurveやAddLinesで、思った図形にしたいです。
 
   横長のFormで右側にPictureboxを配置して試しています
Imports System.Drawing.Drawing2D
Imports System.Drawing

Public Class Form1
    Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
        Dim point1 As New Point(88, 28)
        Dim point2 As New Point(75, 60)
        Dim point3 As New Point(52, 97) : Dim point4 As New Point(83, 43)
        Dim point5 As New Point(118, 43) : Dim point6 As New Point(100, 78)
        Dim point7 As New Point(68, 78) : Dim point8 As New Point(129, 78)
        Dim point9 As New Point(129, 167) : Dim point10 As New Point(72, 83)
        Dim point11 As New Point(72, 170) : Dim point12 As New Point(70, 123)
        Dim point13 As New Point(128, 123) : Dim point14 As New Point(98, 84)
        Dim point15 As New Point(98, 162) : Dim point16 As New Point(70, 160)
        Dim point17 As New Point(122, 160) : Dim point18 As New Point(71, 186)
        Dim point19 As New Point(64, 211) : Dim point20 As New Point(54, 228)
        Dim point21 As New Point(82, 188) : Dim point22 As New Point(91, 211)
        Dim point23 As New Point(85, 225) : Dim point24 As New Point(104, 184)
        Dim point25 As New Point(111, 203) : Dim point26 As New Point(113, 219)
        Dim point27 As New Point(121, 182) : Dim point28 As New Point(138, 196)
        Dim point29 As New Point(137, 209) : Dim point30 As New Point(144, 54)
        Dim point31 As New Point(258, 54) : Dim point32 As New Point(180, 26)
        Dim point33 As New Point(180, 80) : Dim point34 As New Point(226, 27)
        Dim point35 As New Point(226, 79) : Dim point36 As New Point(183, 99)
        Dim point37 As New Point(163, 142) : Dim point38 As New Point(141, 176)
        Dim point39 As New Point(169, 139) : Dim point40 As New Point(169, 231)
        Dim point41 As New Point(254, 122) : Dim point42 As New Point(220, 150)
        Dim point43 As New Point(191, 167) : Dim point44 As New Point(217, 100)
        Dim point45 As New Point(217, 205) : Dim point46 As New Point(216, 220)
        Dim point47 As New Point(234, 223) : Dim point48 As New Point(258, 219)
        Dim point49 As New Point(257, 186)
        Dim curvePoints1 As Point() = {point1, point2, point3}
        Dim curvePoints2 As Point() = {point4, point5, point6}
        Dim curvePoints3 As Point() = {point7, point8, point9}
        Dim curvePoints4 As Point() = {point10, point11}
        Dim curvePoints5 As Point() = {point12, point13}
        Dim curvePoints6 As Point() = {point14, point15}
        Dim curvePoints7 As Point() = {point16, point17}
        Dim curvePoints8 As Point() = {point18, point19, point20}
        Dim curvePoints9 As Point() = {point21, point22, point23}
        Dim curvePoints10 As Point() = {point24, point25, point26}
        Dim curvePoints11 As Point() = {point27, point28, point29}
        Dim curvePoints12 As Point() = {point30, point31}
        Dim curvePoints13 As Point() = {point32, point33}
        Dim curvePoints14 As Point() = {point34, point35}
        Dim curvePoints15 As Point() = {point36, point37, point38}
        Dim curvePoints16 As Point() = {point39, point40}
        Dim curvePoints17 As Point() = {point41, point42, point43}
        Dim curvePoints18 As Point() = {point44, point45, point46, point47, point48, point49}

        Dim bluePen As New Pen(Color.Blue, 3)
        Dim canvas As New Bitmap(PictureBox1.Width, PictureBox1.Height)
        Dim g As Graphics = Graphics.FromImage(canvas)

  

 

投稿者 snowmansnow   (社会人)   投稿日時 2022/1/9 23:57:53
 続きです
        g.DrawCurve(bluePen, curvePoints1, 0.5F)
        g.DrawCurve(bluePen, curvePoints2, 0)
        g.DrawCurve(bluePen, curvePoints3, 0)
        g.DrawCurve(bluePen, curvePoints4, 0)
        g.DrawCurve(bluePen, curvePoints5, 0)
        g.DrawCurve(bluePen, curvePoints6, 0)
        g.DrawCurve(bluePen, curvePoints7, 0)
        g.DrawCurve(bluePen, curvePoints8, 0.5F)
        g.DrawCurve(bluePen, curvePoints9, 0.5F)
        g.DrawCurve(bluePen, curvePoints10, 0.5F)
        g.DrawCurve(bluePen, curvePoints11, 0.5F)
        g.DrawCurve(bluePen, curvePoints12, 0)
        g.DrawCurve(bluePen, curvePoints13, 0)
        g.DrawCurve(bluePen, curvePoints14, 0)
        g.DrawCurve(bluePen, curvePoints15, 0.5F)
        g.DrawCurve(bluePen, curvePoints16, 0)
        g.DrawCurve(bluePen, curvePoints16, 0.5F)
        g.DrawCurve(bluePen, curvePoints17, 0.5F)
        g.DrawCurve(bluePen, curvePoints18, 0.5F)
        bluePen.Dispose()
        g.Dispose()
        'https://dobon.net/vb/dotnet/graphics/drawcurve.html#curve 
        PictureBox1.Image = canvas

        Using gPath As New GraphicsPath()
            Using linePen As New Pen(Color.FromArgb(128, Color.Red), 5)
                gPath.StartFigure()
                gPath.AddCurve(curvePoints1)
                gPath.AddLines(curvePoints2)
                gPath.AddLines(curvePoints3)
                gPath.AddLines(curvePoints4)
                gPath.AddLines(curvePoints5)
                gPath.AddLines(curvePoints6)
                gPath.AddLines(curvePoints7)
                gPath.AddCurve(curvePoints8)
                gPath.AddCurve(curvePoints9)
                gPath.AddCurve(curvePoints10)
                gPath.AddCurve(curvePoints11)
                gPath.AddLines(curvePoints12)
                gPath.AddLines(curvePoints13)
                gPath.AddLines(curvePoints14)
                gPath.AddCurve(curvePoints15)
                gPath.AddLines(curvePoints16)
                gPath.AddCurve(curvePoints17)
                gPath.AddCurve(curvePoints18)
                gPath.CloseFigure()
                e.Graphics.DrawPath(linePen, gPath)
            End Using
        End Using
    End Sub
End Class



投稿者 snowmansnow   (社会人)   投稿日時 2022/1/10 09:36:57

 おはようございます
  もう一度見直して、同じ図形を描けるようになりました。
 
  
             gPath.StartFigure()
                gPath.AddCurve(curvePoints1)
               gPath.StartFigure()
                gPath.AddLines(curvePoints2)
               gPath.StartFigure()
                gPath.AddLines(curvePoints3)
               gPath.StartFigure()
                gPath.AddLines(curvePoints4)
               gPath.StartFigure()
                gPath.AddLines(curvePoints5)
               gPath.StartFigure()
                gPath.AddLines(curvePoints6)
               gPath.StartFigure()
                gPath.AddLines(curvePoints7)
               gPath.StartFigure()
                gPath.AddCurve(curvePoints8)
               gPath.StartFigure()
                gPath.AddCurve(curvePoints9)
               gPath.StartFigure()
               gPath.AddCurve(curvePoints10)
               gPath.StartFigure()
                gPath.AddCurve(curvePoints11)
               gPath.StartFigure()
                gPath.AddLines(curvePoints12)
               gPath.StartFigure()
                gPath.AddLines(curvePoints13)
               gPath.StartFigure()
                gPath.AddLines(curvePoints14)
               gPath.StartFigure()
                gPath.AddCurve(curvePoints15)
               gPath.StartFigure()
                gPath.AddLines(curvePoints16)
               gPath.StartFigure()
                gPath.AddCurve(curvePoints17)
                gPath.StartFigure()
               gPath.AddCurve(curvePoints18)
                '  gPath.CloseFigure() 
                e.Graphics.DrawPath(linePen, gPath)
 

   お騒がせしました。
  またお願いします