Results 1 to 11 of 11

Thread: Color -> Color pixel change (Fast, not loop)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    Grand Rapids, MI
    Posts
    231

    Arrow Color -> Color pixel change (Fast, not loop)

    I want to be able to have a sort of function, where I can type for example.

    changeme(picture1, RGB1, RGB2)

    and it would change all pixels matching RGB1 into RGB2, and it must be fast, looping thru each pixel is painstakinly slow.
    -Karl Blessing aka kb244{fastHACK}
    [email protected]

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Dont put a DoEvents statement in your loops ...
    I shall demonstrate ....
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    This only takes a few seconds on my system :

    Code:
    Option Explicit
    
    Private Declare Function GetPixel Lib "gdi32" (ByVal hDc As Long, ByVal x As Long, ByVal y As Long) As Long
    Private Declare Function SetPixel Lib "gdi32" (ByVal hDc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
    
    
    
    Private Sub Form_Load()
        'draw some coloured pixels
        Dim i As Long
        For i = 0 To 10000
            Picture1.PSet (i * Rnd, i * Rnd), vbRed
        Next i
        
        Me.Show
        DoEvents
        
        'now do the change
        changeMe Picture1, RGB(255, 0, 0), RGB(0, 255, 0)
        
    End Sub
    
    Private Sub changeMe(xPictureBox As PictureBox, srcColour As Long, dstColour As Long)
        Dim i As Long
        Dim j As Long
        Dim nWidth As Long
        Dim nHeight As Long
        Dim hDc As Long
        nWidth = xPictureBox.ScaleWidth
        nHeight = xPictureBox.ScaleHeight
        hDc = xPictureBox.hDc
        
        xPictureBox.Visible = False
        DoEvents
        For i = 0 To nWidth
            For j = 0 To nHeight
                If (GetPixel(hDc, i, j) = srcColour) Then
                    SetPixel hDc, i, j, dstColour
                End If
            Next j
        Next i
        DoEvents
        xPictureBox.Visible = True
    End Sub
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Getpixel/Setpixel are freakingly slow, check out the DMA samples using safe arrays on unlimited realities [/B][/QUOTE] if that's not fast enough, you can code the algoritm in c++ with best performance.
    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.

  5. #5
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Pfff I think my idea's ok
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Nope, it really sucks screw RGB function
    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.

  7. #7
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Okay then how about this :

    Code:
    Private Function myRGB(nRed As Long, nGreen As Long, nBlue As Long) As Long
        myRGB = (nRed * 1) + (nGreen * 256) + (nBlue * 65536)
    End Function
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    worse... use the hex notation
    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.

  9. #9
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    'twas a joke ked

    oh yeah , and what was the thing about that number ?
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  10. #10
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    okay, since nobody'll never get it, i'll give you the last hint: base convertion
    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.

  11. #11
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    What do you mean the last hint ?
    You never game me any ****ing hints
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

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