Graphics question

Hi there,

I'm not sure where is the best place to post, but here goes anyway...

I'm planning to make a graphics program in Visual Basic. Although I used Visual Basic a long time ago, and have somewhat of a knowledge of programming, I am by no means expert (you might say barely past beginner) and have been more of an enthusiast in the past (my real job is design and animation). Recently, I downloaded VB Express and decided to take the plunge again.

Before I start cramming all the information that is out there into this tiny brain of mine, I basically have a few questions before I start re-inventing the wheel:

1. Is there a way (some kind of API or code snippet) that can make curved splines in one's program In particular, not so much bezier splines (which might be useful) but natural cubic splines. I have come across some mathematical sources, but am not that trained in the mathematics. Basically I want to know if there is any way to make smooth curves in VB. Is this something that you need DirectX for Last time I used VB, there was a Lineto command - Hopefully now there is a Curveto command.

2. Is there a routine that handles anti-aliasing in VB One again, is this something that DirectX is needed for Basically anti-aliasing smooths out the edges of lines in computer graphics.

Any help would be most appreciated. Thank you.



Answer this question

Graphics question

  • Schu

    as to the question C# or VB, its really a personal choice, you can do pretty well everything in both languages and ultimately performance is comparable.


  • Schmlughtz

    GDI+ has bezier curves (drawbezier), and cardinal splines (drawcurve). Not that I know what they are. There are some antialiasing modes too, for text and for lines.
    You can always dig around in the source code of paint.Net for inspiration: http://www.eecs.wsu.edu/paint.net/

    e.g.

    Imports System.Drawing.Drawing2D

    Public Class Form1

    Private gp As GraphicsPath

    Private WithEvents b As Button

    Private Mode As Integer

    Private randomGenerator As Random

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    b = New Button

    Me.Controls.Add(b)

    b.Location = New Point(10, 10)

    b.Text = "New One"

    randomGenerator = New Random

    setGP()

    End Sub

    Sub setGP()

    gp = New GraphicsPath

    Dim rand As New Random

    Dim points(6) As PointF

    For i As Integer = 0 To 6

    points(i) = New PointF(rand.Next(0, Me.ClientSize.Width), rand.Next(0, Me.ClientSize.Height))

    Next

    ' 2 bezier curves, first uses points(0), 1, 2 and 3 next uses 3,4,5,6

    gp.AddBeziers(points)

    ' join ends

    gp.CloseFigure()

    End Sub

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

    ' the graphics object is for the form's surface, and is created for us. It exists as a property

    ' of the paintEventArgs...

    e.Graphics.SmoothingMode = Mode

    e.Graphics.FillPath(New SolidBrush(randomcolor), gp)

    e.Graphics.DrawPath(New Pen(randomcolor), gp)

    End Sub

    Private Sub b_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles b.Click

    ' cycle through the available smoothing modes and set a caption

    Mode += 1

    If Mode = 5 Then Mode = 0

    Dim smoothing As System.Drawing.Drawing2D.SmoothingMode = Mode

    Me.Text = smoothing.ToString

    ' create a GraphicsPath object holding some curves

    setGP()

    ' me.refresh will trigger the paint event:

    Me.Refresh()

    End Sub

    Private Function randomcolor() As Color

    Dim bytes(2) As Byte

    randomGenerator.NextBytes(bytes) ' fills the array called bytes with 3 random byte values

    Return Color.FromArgb(255, bytes(0), bytes(1), bytes(2))

    End Function

    End Class


  • Gideon Raveh

    Wow, that looks like a really cool app. It is nice to know that all the sophisticated graphics routines are built in.

    I noticed that the program was written in C#. I'm wondering: A;though this question has probably been asked a million times before, is it best to focus my development plans on Visual Basic or C#


  • Graphics question