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.
Printable View
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.
Dont put a DoEvents statement in your loops ...
I shall demonstrate ....
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
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.
Pfff I think my idea's ok :)
Nope, it really sucks :p screw RGB function
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
worse... use the hex notation
'twas a joke ked :)
oh yeah , and what was the thing about that number ?
okay, since nobody'll never get it, i'll give you the last hint: base convertion
What do you mean the last hint ?
You never game me any ****ing hints :)