Link to home
Start Free TrialLog in
Avatar of kisrael
kisrael

asked on

Getting/Setting Pixels on GIF in VB5

How do I get and set individual pixels on a Picture control in VB5?  I think it has something to do with properly setting ScaleMode and then doing something math, but I can't get Pset and Point to get me what I'm looking for
Avatar of kisrael
kisrael

ASKER

Is it something like this?
widthInPixels = picture1.width/Screen.TwipsPerPixelX
HeightInPixels = picture1.height/Screen.TwipsPerPixelY

for y = 0 to heightInPixels -1
for x = 0 to widthInPixels - 1
                picture1.PSet (x * Screen.TwipsPerPixelX, y * Screen.TwipsPerPixelY)
next
next
Avatar of kisrael

ASKER

Bonus points if someone can tell me how to translate the return value
of the point function (a Long) back into seperate R,G,B values-- even
more points if they can explain why the RGB() fuinction (which goes the
other way) doesn't mention it!!!
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
 getRGB Me.Point(X, Y)
End Sub

Private Sub getRGB(ByVal col As Long)
 
Dim crimson As Byte
Dim verde As Byte
Dim azure As Byte

crimson = col And &HFF
verde = (col And &HFF00) / 256 Mod 256
azure = (col And &HFF0000) / 65536

Text2.Text = " R = " & crimson & " G = " & verde & " B = " & azure
End Sub
jbil looks to have given you the colours, the reason is that colours are actually stored as a 24 bit integer where red is the high bit , green the middle and blue the low.

As an alternative to the method for getting the colour from point, you could use the folowing API call GetPixel which once again returns the 24 bit integer.

picture1.scalemode=3 ' Value for Pixel
lngColour=GetPixel(picture1.hwnd,x,y)

using the API SetPixel you can then play with the colours

lngReturn=SetPixel(picture1.hwnd,x,y,AnyColor(as longValue))
Avatar of kisrael

ASKER

Yeah, I think i figured out all the tools I need.

In case you're wondering, i made this coolish app that takes a
small greyscale GIF and converts it into 5 shades of grey (9 counting
the dithering it does.)

It can then take over control of the mouse, and paint that picture one
grey color at a time on the drawing app at http://www.word.com/pixeltime/

You can see the results at
http://www.word.com/pixeltime/archive/browse.cgi?enlarge=1999%2f07%2f931113580%2e25894&frame=0&email=kisrael%40alienbill%2ecom

ASKER CERTIFIED SOLUTION
Avatar of sp25
sp25

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial