in every thread there someone giving an url to a C way of draing antialiased lines but i wanna know a VB way....
im making a paint prog and i cant stand the ugly lines in the picturebox!:mad:
Please help me!
Printable View
in every thread there someone giving an url to a C way of draing antialiased lines but i wanna know a VB way....
im making a paint prog and i cant stand the ugly lines in the picturebox!:mad:
Please help me!
At 2x - 10x resolution, draw your line (at 2 width to 10 width respectively). Then scale it down to 1x, your 1:1 zoom level. Doing this with StretchBlt or PaintPicture wont produce good results. Rather, do this with an anti-aliased stretch function, I'm sure you can find the source for this. There also may be just a plain old aa'd line function somewhere, if you find one let me know.
proper alised lines work by a process of getting the color value of the pixel and the four around it (above, below, left and right) then taking an average (i think this is it). so if u can use GetPixel and SetPixel ?
You mean anti-aliased don't ya psy? Anyways they actually work the way I showed, and that's the best course of action to take, I believe...
for just a line I believe in Psy's method
for a full rendered picture, it has to be rendered in a higher res and than downscaled.
how do i get the average color then? do i have to get the rgv value or do i use bitblt to mix them?
rgv=rgb
rgb is a 3dvector, get the mean by for each component sum terms and divide by two. To alphablend multiply by factor a for each component in left term, 1-a for right term
ok...ill try that when i get home...:p
it didnt work out fine...
if i have drawwidth = 1 it looked pretty ok but if i set it to a higher value i could see the dots (lines) better and it looked like ****!:mad:
i think it would look better if i used setpixel instead...but if i move the mouse fast when i draw i just get dots:mad:
is there anyway to get lines with setpixel instead? even if it would slow it down?
thanks for your help ;)
Search the net for wu line: these kind of lines are AA.
Note that all line drawing algorithms are derivates from Jack Bresenham's basic line drawing algorithm.
Here are some links to visualize this thread...
http://freespace.virgin.net/hugo.eli...s/x_wuline.htm
A nice tutorial at: http://www.cs.unc.edu/~mcmillan/comp...re6/Lines.html
Mad Compie, are those links to C++ examples? I'd love to see a VB implementation of this :D
One of thos is C++ (the one with things like int etc) the other is some freaky i dont know. A vb version shouldnt be that hard to do.
Well, what I really need is an algorythm to draw lines... simple, non-AA lines :)
It's for my lights system, it's coming along pretty good but it would be better if I had a faster algorythm :p
Basically I find the offset for each step of the rays each light casts (each ray is just a line, it lights up things 'till it hits a wall) using trig, and then use the old linex=linex+xoffset (same thing for the y) algorythm, which is a bit slow... can anyone help?
Here some code to apply Jack Bresenham's non-AA line algorithm:
I rewrote it from C (as seen in http://www.cs.unc.edu/~mcmillan/com...ure6/Lines.htmlmy ) to VB:
PHP Code:
Private Sub Form_Load()
Me.ScaleMode = vbPixels
End Sub
Public Sub lineBresenham(ByVal x0 As Integer, ByVal y0 As Integer, ByVal x1 As Integer, ByVal y1 As Integer, ByVal Color As Long)
Dim dY As Integer
Dim dX As Integer
Dim stepX As Integer
Dim stepY As Integer
Dim Fraction As Integer
dY = y1 - y0
dX = x1 - x0
If (dY < 0) Then
dY = -dY
stepY = -1
Else
stepY = 1
End If
If (dX < 0) Then
dX = -dX
stepX = -1
Else
stepX = 1
End If
dY = dY * 2
dX = dX * 2
Me.PSet (x0, y0), Color
If (dX > dY) Then
Fraction = dY - (dX \ 2)
While (x0 <> x1)
If (Fraction >= 0) Then
y0 = y0 + stepY
Fraction = Fraction - dX
End If
x0 = x0 + stepX
Fraction = Fraction + dY
Me.PSet (x0, y0), Color
Wend
Else
Fraction = dX - (dY \ 2)
While (y0 <> y1)
If (Fraction >= 0) Then
x0 = x0 + stepX
Fraction = Fraction - dY
End If
y0 = y0 + stepY
Fraction = Fraction + dX
Me.PSet (x0, y0), Color
Wend
End If
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
lineBresenham X, Y, X + Rnd * Me.ScaleWidth, Y + Rnd * ScaleHeight, Rnd * &HFFFFFF
End Sub
Thanks ;)