|
-
Sep 2nd, 2001, 10:48 AM
#1
Thread Starter
Frenzied Member
antialiased line...
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!
Please help me!
-
Sep 2nd, 2001, 02:46 PM
#2
Good Ol' Platypus
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.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Sep 2nd, 2001, 03:47 PM
#3
Frenzied Member
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 ?
-
Sep 2nd, 2001, 03:57 PM
#4
Good Ol' Platypus
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...
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Sep 2nd, 2001, 04:50 PM
#5
Frenzied Member
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.
Sanity is a full time job
Puh das war harter Stoff!
-
Sep 3rd, 2001, 03:59 AM
#6
Thread Starter
Frenzied Member
colors...
how do i get the average color then? do i have to get the rgv value or do i use bitblt to mix them?
-
Sep 3rd, 2001, 04:00 AM
#7
Thread Starter
Frenzied Member
-
Sep 3rd, 2001, 04:41 AM
#8
transcendental analytic
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
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Sep 3rd, 2001, 06:45 AM
#9
Thread Starter
Frenzied Member
thanks
ok...ill try that when i get home...
-
Sep 3rd, 2001, 02:03 PM
#10
Thread Starter
Frenzied Member
-
Sep 7th, 2001, 11:27 AM
#11
Fanatic Member
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
-
Sep 8th, 2001, 02:20 PM
#12
Frenzied Member
Mad Compie, are those links to C++ examples? I'd love to see a VB implementation of this
-
Sep 8th, 2001, 03:16 PM
#13
Frenzied Member
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.
-
Sep 8th, 2001, 04:38 PM
#14
-
Sep 9th, 2001, 06:02 AM
#15
Fanatic Member
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
Last edited by Mad Compie; Sep 9th, 2001 at 06:07 AM.
-
Sep 10th, 2001, 10:28 AM
#16
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|