Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Picture, each pixels color

Status
Not open for further replies.

eequalsmc2plus1

Programmer
Aug 26, 2002
28
ZA
Hi

Anyone know how to get the color of each pixel in a picture ?
I tried a while ago, couldnt find a way 2 do it in VB but could do it in C++. Want it in VB though.
Doesnt matter if it returns the RGB value or the other way of representing colors, whatever as long as it gives me a value for each pixel.

Thanks
Damian
 
this worked for me, not as fast as using api funtions though:

you should do something with the TempRed, TempBlue, and TempGreen during the second loop. But they will be 0 - 255 RGB values.
I think InputPixels() should be as Long

For X = 1 To Picture1.Width
For Y = 1 To Picture1.Height
InputPixels(X, Y) = Picture1.Point(X, Y)
Next Y
Next X

For X = 0 To Picture1.Width - 1
For Y = 0 To Picture1.Height - 1
TempRed = (InputPixels(X, Y) And &HFF)
TempGreen = (((InputPixels(X, Y) And &HFF00) / &H100)
Mod &H100)
TempBlue = (((InputPixels(X, Y) And &HFF0000) /
&H10000) Mod &H100)

Next Y
Next X
 

Here is an example for you...
Place Picture1, Picture2, and Command1 on form and place this code inside. Don't forget to replace the path to a file in the loadpicture function...
[tt]

Private Sub Form_Load()
Picture1.ScaleMode = vbPixels
Picture1.Picture = LoadPicture("Your Path To File")
Picture2.ScaleMode = vbPixels
End Sub

Private Sub Command1_Click()

Dim X As Long, Y As Long

For Y = 0 To Picture1.ScaleHeight
For X = 0 To Picture1.ScaleWidth
Picture2.PSet (X, Y), Picture1.Point(X, Y)
DoEvents
Next X
Next Y
End Sub
[/tt]

Good Luck


 
Another question.
Those values that the point command returns.
Black is 0
White is 16777215

here some others i got
Brown is 128
Red is 16512
Purple is 8388608
Yellow 65535

Does anyone know how they work, would have though the darkest, black would be 0 and then as they get lighter the value gets higher, but until white. But that doesnt work purple is way darker than yellow and look at their values.

All i need is a general thing so that I can spilt those 16 777 215 values into about 10.
EG ...
0 to 1 000 000 is black
1 000 000 to 2 000 000 is brown
2 000 000 to 3 000 000 is purple
3 000 000 to 4 000 000 is red
4 000 000 to 5 000 000 is blue
5 000 000 to 6 000 000 is green
6 000 000 to 7 000 000 is yellow
etc ....
15 000 000 to 16 000 000 is white

Is that possible ??? And if so how ?

Thanks 4 any help
Damian
 

Actually these are long values based upon hex values or RGB values.
[tt]
MyColor = RGB(0, 0, 0) 'Should be black
MyColor = RGB(255, 0, 0) 'Red
MyColor = RGB(0, 255, 0) 'Green
MyColor = RGB(0, 0, 255) 'Blue
[/tt]

There is an example somewhere on how to extract the RGB colors from a long value around here somewhere. I know it uses division and based on that and what each main color represents above I think you can figure it out.

Good Luck


 
see the post from wtlebo13.

MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Oh, thanks.

Dont I look like an idiot .... :)
AND I feel like and even BIGGER one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top