|
-
Jun 7th, 2001, 12:12 PM
#1
Thread Starter
Addicted Member
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.
-
Jun 8th, 2001, 03:28 AM
#2
Retired VBF Adm1nistrator
Dont put a DoEvents statement in your loops ...
I shall demonstrate ....
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Jun 8th, 2001, 04:10 AM
#3
Retired VBF Adm1nistrator
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]
-
Jun 8th, 2001, 04:41 AM
#4
transcendental analytic
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.
-
Jun 8th, 2001, 04:43 AM
#5
Retired VBF Adm1nistrator
Pfff I think my idea's ok
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Jun 8th, 2001, 04:47 AM
#6
transcendental analytic
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.
-
Jun 8th, 2001, 04:56 AM
#7
Retired VBF Adm1nistrator
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]
-
Jun 8th, 2001, 05:57 AM
#8
transcendental analytic
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.
-
Jun 8th, 2001, 05:59 AM
#9
Retired VBF Adm1nistrator
'twas a joke ked 
oh yeah , and what was the thing about that number ?
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Jun 11th, 2001, 05:11 PM
#10
transcendental analytic
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.
-
Jun 12th, 2001, 02:44 AM
#11
Retired VBF Adm1nistrator
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|