Fastest bitmap update as possible 
Author Message
 Fastest bitmap update as possible

Hi there!

    What would be the fastest way to update a PictureBox's DC? I've got to
show up to 300 points as fast as possible...

    I've got this code:

    Form Code:

        Option Explicit

        Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long,
ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As
Long
        Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long,
ByVal nIDEvent As Long) As Long

        Private Sub Form_Load()

            g_lWidth = Picture1.ScaleWidth
            g_lHeight = Picture1.ScaleHeight
            g_hDC = Picture1.hDc

            SetTimer Me.hwnd, 0, 1, AddressOf TimerProc

        End Sub

        Private Sub Form_Unload(Cancel As Integer)
            KillTimer Me.hwnd, 0
        End Sub

    Module Code:

        Option Explicit

        Private Declare Function SetPixel Lib "gdi32" (ByVal hDc As Long,
ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long

        Public g_lWidth As Long
        Public g_lHeight As Long
        Public g_hDC As Long

        Public Sub TimerProc(ByVal hwnd As Long, _
                             ByVal nIDEvent As Long, _
                             ByVal uElapse As Long, _
                             ByVal lpTimerFunc As Long)

            Dim I As Long
            Dim lColor As Long

            lColor = RGB(Int(Rnd * 256), Int(Rnd * 256), Int(Rnd * 256))

            Form1.Picture1.AutoRedraw = False

            For I = 1 To 300
                SetPixel g_hDC, I, I, lColor
            Next I

            Form1.Picture1.AutoRedraw = True

        End Sub

    Would be that faster if I create a compatible dc, bitmap, ... then use
bitblt... ? I don't remember the API function that prevent a control from
refreshing but would that help a little bit?

    Thanks a lot!

--
Best Regards
Zoury
_________________________________
Thanks to post replies to the newsgroup :O)



Mon, 21 Feb 2005 01:09:15 GMT  
 Fastest bitmap update as possible

Quote:
>     What would be the fastest way to update a PictureBox's DC? I've got to
> show up to 300 points as fast as possible...

<snip>

Quote:
>     Would be that faster if I create a compatible dc, bitmap, ... then use
> bitblt... ? I don't remember the API function that prevent a control from
> refreshing but would that help a little bit?

You could probably get a little more speed by using a memory DC however
you'd be pushing a lot more data about.  The fastest method possible would
be to use a DIBSection and overwrite the a local array descriptor with the
data pointer to bypass memory copying however this is a little overkill for
300 points.
Migrating the drawing code to a C++ DLL at that point would also make things
easier since you have far better control over pointers.
If your picture box is set to AutoRedraw() then calling LockWindowUpdate()
wouldn't speed things up at all, if anything the reverse.
Hope this helps,

    Mike

 -- EDais --

 - Microsoft Visual Basic MVP -
WWW: Http://EDais.earlsoft.co.uk/




Mon, 21 Feb 2005 02:01:56 GMT  
 Fastest bitmap update as possible
Thanks Mike!

--
Best Regards
Zoury
_________________________________
Thanks to post replies to the newsgroup :O)


Quote:
> >     What would be the fastest way to update a PictureBox's DC? I've got
to
> > show up to 300 points as fast as possible...

> <snip>

> >     Would be that faster if I create a compatible dc, bitmap, ... then
use
> > bitblt... ? I don't remember the API function that prevent a control
from
> > refreshing but would that help a little bit?

> You could probably get a little more speed by using a memory DC however
> you'd be pushing a lot more data about.  The fastest method possible would
> be to use a DIBSection and overwrite the a local array descriptor with the
> data pointer to bypass memory copying however this is a little overkill
for
> 300 points.
> Migrating the drawing code to a C++ DLL at that point would also make
things
> easier since you have far better control over pointers.
> If your picture box is set to AutoRedraw() then calling LockWindowUpdate()
> wouldn't speed things up at all, if anything the reverse.
> Hope this helps,

>     Mike

>  -- EDais --

>  - Microsoft Visual Basic MVP -
> WWW: Http://EDais.earlsoft.co.uk/





Mon, 21 Feb 2005 02:01:42 GMT  
 Fastest bitmap update as possible
You could use InvalidateRect, that would help a bit. Your best bet is to get
clsDIB from http://edais.earlsoft.co.uk, read the DIB tutorial, then use
GetDIBits to manipulate the byte array behind the picture directly, which is
zippy-quick.

Max Bolingbroke


Quote:
> Hi there!

>     What would be the fastest way to update a PictureBox's DC? I've got to
> show up to 300 points as fast as possible...

>     I've got this code:

>     Form Code:

>         Option Explicit

>         Private Declare Function SetTimer Lib "user32" (ByVal hwnd As
Long,
> ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
As
> Long
>         Private Declare Function KillTimer Lib "user32" (ByVal hwnd As
Long,
> ByVal nIDEvent As Long) As Long

>         Private Sub Form_Load()

>             g_lWidth = Picture1.ScaleWidth
>             g_lHeight = Picture1.ScaleHeight
>             g_hDC = Picture1.hDc

>             SetTimer Me.hwnd, 0, 1, AddressOf TimerProc

>         End Sub

>         Private Sub Form_Unload(Cancel As Integer)
>             KillTimer Me.hwnd, 0
>         End Sub

>     Module Code:

>         Option Explicit

>         Private Declare Function SetPixel Lib "gdi32" (ByVal hDc As Long,
> ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long

>         Public g_lWidth As Long
>         Public g_lHeight As Long
>         Public g_hDC As Long

>         Public Sub TimerProc(ByVal hwnd As Long, _
>                              ByVal nIDEvent As Long, _
>                              ByVal uElapse As Long, _
>                              ByVal lpTimerFunc As Long)

>             Dim I As Long
>             Dim lColor As Long

>             lColor = RGB(Int(Rnd * 256), Int(Rnd * 256), Int(Rnd * 256))

>             Form1.Picture1.AutoRedraw = False

>             For I = 1 To 300
>                 SetPixel g_hDC, I, I, lColor
>             Next I

>             Form1.Picture1.AutoRedraw = True

>         End Sub

>     Would be that faster if I create a compatible dc, bitmap, ... then use
> bitblt... ? I don't remember the API function that prevent a control from
> refreshing but would that help a little bit?

>     Thanks a lot!

> --
> Best Regards
> Zoury
> _________________________________
> Thanks to post replies to the newsgroup :O)



Mon, 21 Feb 2005 14:39:44 GMT  
 Fastest bitmap update as possible
Hi Zoury,

maybe I'm too late, but a faster way to set pixels is using:

SetPixelV Lib "gdi32" Alias "SetPixelV" (ByVal hdc As Long, ByVal x As Long,
ByVal y As Long, ByVal crColor As Long)

instead of SetPixel. It's  about 5-10 times faster, but has some
restrictions ( color depth ).

best regards
Frank


Quote:
> Thanks Mike!

> --
> Best Regards
> Zoury
> _________________________________
> Thanks to post replies to the newsgroup :O)


> > >     What would be the fastest way to update a PictureBox's DC? I've
got
> to
> > > show up to 300 points as fast as possible...

> > <snip>

> > >     Would be that faster if I create a compatible dc, bitmap, ... then
> use
> > > bitblt... ? I don't remember the API function that prevent a control
> from
> > > refreshing but would that help a little bit?

> > You could probably get a little more speed by using a memory DC however
> > you'd be pushing a lot more data about.  The fastest method possible
would
> > be to use a DIBSection and overwrite the a local array descriptor with
the
> > data pointer to bypass memory copying however this is a little overkill
> for
> > 300 points.
> > Migrating the drawing code to a C++ DLL at that point would also make
> things
> > easier since you have far better control over pointers.
> > If your picture box is set to AutoRedraw() then calling
LockWindowUpdate()
> > wouldn't speed things up at all, if anything the reverse.
> > Hope this helps,

> >     Mike

> >  -- EDais --

> >  - Microsoft Visual Basic MVP -
> > WWW: Http://EDais.earlsoft.co.uk/





Fri, 04 Mar 2005 03:01:58 GMT  
 Fastest bitmap update as possible
Frank..

Quote:
> maybe I'm too late, but a faster way to set pixels is using:

Wrong, this would be about ~50-100 times _slower_ than the original method.

Quote:
> instead of SetPixel. It's  about 5-10 times faster, but has some
> restrictions ( color depth ).

Nope, the only difference between SetPixel and SetPixelV() is that the
latter doesn't return the old colour value - It gives a slight speed
increase, but not 5-10 times!  Maybe 5-10 times faster than _PSet()_ but
even less so when compiled.

    Mike

 -- EDais --

 - Microsoft Visual Basic MVP -
WWW: Http://EDais.earlsoft.co.uk/




Fri, 04 Mar 2005 04:12:19 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. How can I make a bitmap spalsh screen load faster

2. Fast Bitmap Manipulation

3. Hello Plz I want to help as fast as possible Visual Basic

4. VB4 - Is it possible to fast forward thur CD

5. Wanted Some Info - AS FAST AS POSSIBLE

6. How to find files as fast as possible

7. JPEG to array, the fastest way possible

8. Possible to edit a bitmap's palette?

9. Fast Way to update one field in one record

10. Linking computers by modem and updating tables fast

11. Linking computers by modem and updating tables fast

12. Fastest known sort for database access: any interest in VB implementation [updated]

 

 
Powered by phpBB® Forum Software