Results 1 to 7 of 7

Thread: VB.NET graphics slow compared to VB6

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Location
    Trenton, NJ
    Posts
    4

    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:
    1. mypicture.autoredraw = true   ' set at design time
    2. for x = 1 to 600
    3.   for y = 1 to 400
    4.     iterations=calculatepoint(x,y)  ' this function is where all the heavy math happens
    5.     mypicture.pset (x,y), colorlist(iterations)  ' there's more logic going on here, but this is the important part
    6.   next y
    7.   doevents
    8. next x

    And here's the VB.NET code

    VB Code:
    1. bmap = new bitmap(600,400,system.drawing.imaging.pixelformat.format24bpprgb)
    2. mypicture.image = bmap  ' these two lines done in form.load
    3. for x = 1 to 600
    4.   for y = 1 to 400
    5.     iterations=calculatepoint(x,y)  ' this function is where all the heavy math happens
    6.     bmap.setpixel(x,y,colorlist(iterations))  ' again, this is the important part
    7.   next y
    8.   mypicture.refresh()
    9.   system.windows.forms.application.doevents()
    10. next x

    Is this the correct approach to this manner of drawing? Is there something I may be missing?

    Thanks,
    Dennis

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: VB.NET graphics slow compared to VB6

    [i]
    VB Code:
    1. bmap = new bitmap(600,400,system.drawing.imaging.pixelformat.format24bpprgb)
    2. mypicture.image = bmap  ' these two lines done in form.load
    3. for x = 1 to 600
    4.   for y = 1 to 400
    5.     iterations=calculatepoint(x,y)  ' this function is where all the heavy math happens
    6.     bmap.setpixel(x,y,colorlist(iterations))  ' again, this is the important part
    7.   next y
    8.   mypicture.refresh()
    9.   system.windows.forms.application.doevents()
    10. 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:
    1. Dim bmp as bitmap = new bitmap(...)
    2.  
    3. for i = ...
    4. for j = ....
    5. 'do drawing here using the SetPixel() function of the bitmap
    6. next j
    7. next i
    8.  
    9. pic.image = bmp
    10. ...
    Last edited by wossname; Apr 29th, 2004 at 02:55 PM.
    I don't live here any more.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Location
    Trenton, NJ
    Posts
    4
    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.

  4. #4
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    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.

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Location
    Trenton, NJ
    Posts
    4
    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.

  6. #6
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    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.

  7. #7

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Location
    Trenton, NJ
    Posts
    4
    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
  •  



Click Here to Expand Forum to Full Width