As keghn said…
You need to profile and optimize your code.
VB.NET is an interpreted language; it has no native compiler etc so it’s not the fastest language by a long mark. You could use another faster language; even JAVA is generally faster than VB.NET but preferably something like C++.
https://adtmag.com/articles/2002/08/01/speed-up-your-vbnet-code.aspxhttps://msdn.microsoft.com/en-us/library/aa289513(v=vs.71).aspxThere are loads of web sites offering information on code optimization for specific languages but there are some basic rules that apply to all languages.
Make sure you are declaring the best/ fastest variable types for each purpose.
Check you are passing the correct variable types to subs/ functions.
Some built in functions can be very easy to use but very slow.
Remove as much math/ code from the inside of loops as possible.
Use pre-calculated ‘look up’ tables/ arrays where ever possible to avoid complex math.
Check your loops are not over running.
Limit sub calls they are usually very slow, use in-line code where possible.
Avoid/ limit classes; these are again very easy to use but very slow.
Re-think your algorithms… is there a faster way?
Etc…
Avoid using multiple comparisons in an IF statement on the same line; most compilers will check every comparison even if the first one is not matched.
.If xPos > 0 And xPos < image.Width - 1 And Ypos > 0 And Ypos < image.Height - 1 Then
Nest these into separate IF’s… I know it makes your code longer but it also makes it faster.
Remove unnecessary calculations from within your loops... ie...
Public Shared Function mark_dark_pixel(ByVal x As Integer, ByVal y As Integer, ByVal bmp1 As Bitmap, ByVal marker As Byte)
For i As Integer = 0 To marker
yi=y+i <<<<<<<<<
For j As Integer = 0 To marker
Try
bmp1.SetPixel(x + j, yi, Color.Green)
Catch ex As Exception
End Try
Next
Next
Return bmp1
End Function
Write small test programs where you can accurately time methods and functions against each other inside a set loop size to find the fastest coding schema. Use an accurate timer to time loops and print the results so you can see which sections are slowing your code down… then optimize those sections.
Code optimization can often take longer than the actual code production and it’s a good habit to optimize as you go along once you are familiar with the bottlenecks and foibles of your chosen language.
I personally really enjoy code profiling.