Google Answers Logo
View Question
 
Q: Visual Basic 6 Getpixel API Function ( No Answer,   1 Comment )
Question  
Subject: Visual Basic 6 Getpixel API Function
Category: Computers > Programming
Asked by: crushenator-ga
List Price: $15.00
Posted: 21 May 2006 15:01 PDT
Expires: 22 May 2006 23:52 PDT
Question ID: 731090
I'm trying to make a visual basic program that calls the Getpixel API
function to check the color of pixel 0, 0, save the information to an
array and then move on to the next pixel 1, 0 and so on untill it
finishes scanning an area I designate.
                                             
Heres an example of the code I have so far:
tPOS.x = 1
tPOS.y = 1
x:
    lDC = GetWindowDC(0)                   'Gets the DC of the current window
    lColor = GetPixel(lDC, tPOS.x, tPOS.y) 'Gets the current pixel color
    tPOS.x = tPOS.x + 1                    'Moves one pixel along x axis
    If tPOS.x = 300 Then tPOS.y = tPOS.y + 1 reaches pixel 300, moves
down 1 y
    If tPOS.x = 300 Then tPOS.x = 1           'Resets the x axis to 1
    If tPOS.y = 5 Then GoTo y                 'If it reaches y axis 5 goto y
    GoTo x                                    'Go to x to repeat loop
y:
    Beep                                      'finished section
    MsgBox "Done"

End Sub

As you can see it scans 300 along the X axis and about 4 along the Y
axis. The problem with this example of code is it takes too long! Even
when I compile it takes 9 seconds to run the above example through,
when ideally I'd want it to be able to scan 700 x 700 pixels in a
matter of a few seconds at most.

My question is, how can I make this code run faster? or is there a
more efficient way in visual basic 6 to do what I'm doing? Thanks!
Answer  
There is no answer at this time.

Comments  
Subject: Re: Visual Basic 6 Getpixel API Function
From: frde-ga on 22 May 2006 05:35 PDT
 
That is not nice code
- I will use GoTo if it simplifies things - but never otherwise
- this is an 'otherwise' situation

This is probably a question posed by a 'teacher' 
- in other words it is pure homework

lDC = GetWindowDC(0)  ' do it once                 
For L9 = 1 To 300
    For L8 = 1 To 4
        lColor = GetPixel(lDC, L9, L8) 
        ' do something
    Next
Next

However GetWindowDC(0) is suspect

Also one would expect the base to be 0 rather than 1

eg:
  For L9 = 0 To 299

Also tPOS.x and tPOS.y are probably instances of Classes

I see no sign of an Array - but you will need an Array of Longs to
store a Windows colour - OLE_COLOR is the Alpha answer there

Your teacher has given you some lousy code
- what is required is a functional re-write

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy