|
-
Aug 2nd, 2001, 11:58 PM
#1
Thread Starter
Lively Member
Aquiring the color of pixels of large area ... Quickly ?
I tried to program an image analyzer with VB when I met a problem, I don’t know if its cause is the speed of VB. Immediate assistance required.
That is a section of my program
Public Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long) As Long
Public Declare Function GetWindowDC Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long
Public ImageStyle As String
Public MoniX As Integer
Public MoniY As Integer
Sub ScreenScan()
For y = MoniY To MoniY + 150
For x = MoniX To MoniX + 200
Dim hDCScreen As Long
Dim lngColor As Long
hDCScreen = GetWindowDC(0) 'gets the DC of the screen
lngColor = GetPixel(hDCScreen, x, y)
ReleaseDC 0, hDCScreen 'releases the DC: this must be done
MA.PSet (15 * (x - MoniX), 15 * (y - MoniY)), lngColor
Next x
Next y
End Sub
But this seems to take laughable amount of time to get the color of every point on the screen.
Because every time I want the color of a point, it scan the screen and then give the color of the point I want. But What I wanted to do is to scan the screen once and report the color of every point on the screen.
What Can I do to aquire color of large section of the screen QUICKLY ?
I am afraid I need Direct X
Thanks for your time.
What are the universe used for and why it's here ?
-
Aug 3rd, 2001, 01:47 AM
#2
Fanatic Member
Re: Aquiring the color of pixels of large area ... Quickly ?
Code:
Public Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long) As Long
Public Declare Function GetWindowDC Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long
Public ImageStyle As String
Public MoniX As Integer
Public MoniY As Integer
Sub ScreenScan()
Dim hDCScreen As Long
Dim lngColor As Long
hDCScreen = GetWindowDC(0) 'gets the DC of the screen
For y = MoniY To MoniY + 150
For x = MoniX To MoniX + 200
lngColor= GetPixel(hDCScreen, x, y)
MA.PSet (15 * (x - MoniX), 15 * (y - MoniY)), lngColor
Next x
Next y
ReleaseDC 0, hDCScreen 'releases the DC: this must be done
End Sub
You may want the try the code above. It should improve the speed a little. Although I have not tryed the code, it should increase the speed, because you are no longer running though the dim, or getting/releasing the dc each loop. I don't know how much this will help.
-
Aug 3rd, 2001, 02:28 AM
#3
Retired VBF Adm1nistrator
Might I also suggest , that you dont use PSet while you're getting the colour of the pixels. Get the colours, and store them in a 2 dimensional array, and then once you've got the pixel colours, then do something with them.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Aug 3rd, 2001, 05:32 AM
#4
Thread Starter
Lively Member
Still too slow
I am afraid that is still a lot slower then an standard digital camera ...
Can anyone help ?
What are the universe used for and why it's here ?
-
Aug 3rd, 2001, 07:32 AM
#5
Member
Check the examples near the end of this tutorial:
rookscape.com/vbgaming/tutAY.php
It uses API (doesn't require DirectX), and shows some fast ways of getting to the color data ...
-Bryk
-
Aug 3rd, 2001, 08:16 PM
#6
Thread Starter
Lively Member
Nothing ! Nothing Works !
Oh man , Nothing worked so far , the pointer method do not support the entire screen !
What are the universe used for and why it's here ?
-
Aug 3rd, 2001, 08:37 PM
#7
Good Ol' Platypus
A 150x200 pic that I have (24bit colour) takes under 50 ms with the pointer method. The last method is a good one.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Aug 3rd, 2001, 08:52 PM
#8
Good Ol' Platypus
You cant get that fast without DIRECT DIRECT memory access, what Byrkovian has suggested is the method I have been using, the fastest I've seen. If you need faster results, Assembly is the way to go.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Aug 4th, 2001, 03:33 AM
#9
transcendental analytic
Bitblt suckers, have you ever heard of it? 
look up in msdn for syntax
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.
-
Aug 4th, 2001, 01:27 PM
#10
Good Ol' Platypus
Well I was going to use if for my 'SastraxiSmooth' thingey but since ZSNES went open source I've downloaded the C++ package and am currently adding SS into it !
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Aug 4th, 2001, 04:47 PM
#11
Thread Starter
Lively Member
I meant I can't use it ...
I want to capture the screen , and the pointer don't work with the screen itself , you have to load the picture into your program before using it !
Arrrrg !
What are the universe used for and why it's here ?
-
Aug 4th, 2001, 04:53 PM
#12
transcendental analytic
Exactly, and that's where bitblt will work for you, create memory DC and blit over the display data to it then go access the bitmap.
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.
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
|