Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / COM / September 2005



Tip: Looking for answers? Try searching our database.

Point method for getting RGB values for a colour

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rob - 26 Sep 2005 13:31 GMT
Hi.

I'm using VB 6.0. I am using the POINT method to get the colour of a
specific point in one of my pictureboxes. How can I change the data that
POINT returns to the 3 RGB values of that colour?

Thanks in advance,
Rob.

PS:
picturebox1.backcolor=rgb(100,100,100)
msgbox picturebox1.point(1,1)  //it returns 6579300 :(
Norm Cook - 26 Sep 2005 13:55 GMT
Something along these lines:

Dim clr As Long
Dim Red As Byte, Green As Byte, Blue As Byte
clr = vbWhite
Red = clr And &HFF&
Green = (clr And &HFF00&) \ 256
Blue = (clr And &HFF0000) \ 65536
Debug.Print Red, Green, Blue

> Hi.
>
[quoted text clipped - 8 lines]
> picturebox1.backcolor=rgb(100,100,100)
> msgbox picturebox1.point(1,1)  //it returns 6579300 :(
Karl E. Peterson - 27 Sep 2005 20:05 GMT
Hi Rob --

> I'm using VB 6.0. I am using the POINT method to get the colour of a
> specific point in one of my pictureboxes. How can I change the data
> that POINT returns to the 3 RGB values of that colour?

I think the easiest way is to just ask for it, directly.

  Public Declare Function GetPixelRGB Lib "gdi32" Alias "GetPixel" (ByVal hDC As
Long, ByVal x As Long, ByVal y As Long) As RGB32

  Public Type RGB32
     Red As Byte
     Green As Byte
     Blue As Byte
     Pad As Byte
  End Type

See http://vb.mvps.org/samples/RGB for complete implementation.

> PS:
> picturebox1.backcolor=rgb(100,100,100)
> msgbox picturebox1.point(1,1)  //it returns 6579300 :(

Yep, that's how VB encodes colors into a Long.  You can break it apart with math as
Norm shows, or like this:

  Public Function SplitColors(ByVal Value As Long) As RGB32
     Call CopyMemory(SplitColors, Value, 4)
  End Function

Later...   Karl
Signature

Working Without a .NET?
http://classicvb.org/petition

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.