PDA

Click to See Complete Forum and Search --> : Aquiring the color of pixels of large area ... Quickly ?


Cooker
Aug 2nd, 2001, 11:58 PM
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.

Gaming_World
Aug 3rd, 2001, 01:47 AM
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.

plenderj
Aug 3rd, 2001, 02:28 AM
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.

Cooker
Aug 3rd, 2001, 05:32 AM
I am afraid that is still a lot slower then an standard digital camera ...
Can anyone help ?

Brykovian
Aug 3rd, 2001, 07:32 AM
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

Cooker
Aug 3rd, 2001, 08:16 PM
Oh man , Nothing worked so far , the pointer method do not support the entire screen !

Sastraxi
Aug 3rd, 2001, 08:37 PM
A 150x200 pic that I have (24bit colour) takes under 50 ms with the pointer method. The last method is a good one.

Sastraxi
Aug 3rd, 2001, 08:52 PM
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.

kedaman
Aug 4th, 2001, 03:33 AM
Bitblt suckers, have you ever heard of it? :p
look up in msdn for syntax

Sastraxi
Aug 4th, 2001, 01:27 PM
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 :D!

Cooker
Aug 4th, 2001, 04:47 PM
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 !

kedaman
Aug 4th, 2001, 04:53 PM
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.