Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Getting a pixel color

Total Hit ( 3946)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


The Point method returns the color value of a given pixel, but is rather slow because it has to convert its argument from twips (or whatever ScaleMode is currently active) to pixels, and also because its argument are treated as Single quantities, and must therefore converted. When you have to retrieve the color value of many pixels you should use the GetPixel API function instead. Here is its declaration:

Click here to copy the following block
Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, _
  ByVal y As Long) As Long

The following code example counts the number of red pixels on the active form:
' assumes that form's ScaleMode
' is set to 3 - Pixels
Dim x As Long, y As Long
Dim h As Long, count As Long
' cache form's hDC property
h = Me.hdc
For y = 0 To ScaleHeight - 1
  For x = 0 To ScaleWidth - 1
    If GetPixel(h, x, y) = vbRed Then
      count = count + 1
    End If
  Next
Next

It is about three times faster than the equivalent code that uses the Point method. Note that we can have this speed increment also because we cache the hDC property into a variable.


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.