|
-
Apr 29th, 2004, 02:36 PM
#1
Thread Starter
New Member
VB.NET graphics slow compared to VB6
I have an app originally written in VB6 that draws the Mandelbrot set. I loop through each pixel in a picture control, calculate the proper color for that pixel, and set the color, doing a refresh after each line. When I converted this to .NET it drew considerably slower. If I happen to minimize the app so that it doesn't have to draw anything the speed is fine.
Here are the times I'm getting for a particular view:
VB6 3 seconds
.NET (foreground) 14 seconds
.NET (background) 2 seconds
Here's a simplified piece of the VB6 code:
VB Code:
mypicture.autoredraw = true ' set at design time
for x = 1 to 600
for y = 1 to 400
iterations=calculatepoint(x,y) ' this function is where all the heavy math happens
mypicture.pset (x,y), colorlist(iterations) ' there's more logic going on here, but this is the important part
next y
doevents
next x
And here's the VB.NET code
VB Code:
bmap = new bitmap(600,400,system.drawing.imaging.pixelformat.format24bpprgb)
mypicture.image = bmap ' these two lines done in form.load
for x = 1 to 600
for y = 1 to 400
iterations=calculatepoint(x,y) ' this function is where all the heavy math happens
bmap.setpixel(x,y,colorlist(iterations)) ' again, this is the important part
next y
mypicture.refresh()
system.windows.forms.application.doevents()
next x
Is this the correct approach to this manner of drawing? Is there something I may be missing?
Thanks,
Dennis
-
Apr 29th, 2004, 02:50 PM
#2
Re: VB.NET graphics slow compared to VB6
[i]
VB Code:
bmap = new bitmap(600,400,system.drawing.imaging.pixelformat.format24bpprgb)
mypicture.image = bmap ' these two lines done in form.load
for x = 1 to 600
for y = 1 to 400
iterations=calculatepoint(x,y) ' this function is where all the heavy math happens
bmap.setpixel(x,y,colorlist(iterations)) ' again, this is the important part
next y
mypicture.refresh()
system.windows.forms.application.doevents()
next x
[/B]
You are calling PictureBox.refresh and Doevents 600 times!
Dude theres your problem. 
Draw the stuff to a bitmap object in the background and then set the image property to the bitmap when its finished. That will be super fast...
VB Code:
Dim bmp as bitmap = new bitmap(...)
for i = ...
for j = ....
'do drawing here using the SetPixel() function of the bitmap
next j
next i
pic.image = bmp
...
Last edited by wossname; Apr 29th, 2004 at 02:55 PM.
I don't live here any more.
-
Apr 29th, 2004, 03:15 PM
#3
Thread Starter
New Member
That's an idea, although I would like to see the points as they're being calculated to some degree. Some of the really deep field views can take a long time to calculate.
I did try doing another version of this where I spawn off a thread that does the loop minus the refresh call, and the other thread calls refresh once every 1/10 second. This runs better on the wide views where total time is small, but on the deeper views it can increase the time quite a bit.
The fact that the drawing routines in VB6 take up effectively no time has me wondering if I'm using the correct set of functions / classes to do this type of drawing.
-
Apr 30th, 2004, 01:51 AM
#4
By the way, are you compiling to DEBUG or RELEASE in .net?
This can make a big difference sometimes.
Release is fast but you don't get the debug facilities, but once your program runs bug free you won't need debug mode.
I don't live here any more.
-
Apr 30th, 2004, 08:06 AM
#5
Thread Starter
New Member
I tried it both ways but it didn't seem to make a lot of difference. I did notice on one of the deeper views that it runs much faster outside of the development environment than inside, which I guess is to be expected.
-
Apr 30th, 2004, 08:16 AM
#6
Anyway, its unforgiveable to run doevents and refresh 600 times.
(IMHO )
Screw the user he'll have to wait for all the pixels to show up at once!
I don't live here any more.
-
Apr 30th, 2004, 08:21 AM
#7
Thread Starter
New Member
Actually, I did find one thing that trimmed off a couple of seconds. Rather than calling mypicture.Refresh() I called mypicture.CreateGraphics.DrawImage(bmap, 0, 0).
Thanks for your suggestions.
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
|