[Gambas-user] get the color from a pixel in DrawingArea control

Benoit Minisini gambas at ...1...
Tue Mar 27 18:29:46 CEST 2007


On lundi 26 mars 2007, Arief Bayu Purwanto wrote:
> Thank you for your solution, I'll check it out once I back home and
> give report ASAP.
>
> On 3/26/07, timothy <timothy.marshal-nichols at ...247...> wrote:
> > > -----Original Message-----
> > > From: gambas-user-bounces at lists.sourceforge.net [mailto:gambas-user-
> > > bounces at lists.sourceforge.net] On Behalf Of Arief Bayu Purwanto
> > > Sent: Sunday, 25 March 2007 10:43 AM
> > > To: gambas-user at lists.sourceforge.net
> > > Subject: [Gambas-user] get the color from a pixel in DrawingArea
> >
> > control
> >
> > > Dear member,
> > >
> > > I'm trying to create a paint application. Right now I'm encounter a
> > > problem when I want to aplly  a photo bucket tool. Because It's need
> > > current color of a pixel to do the job. I'm searching around the help
> > > document, but found nothing. Could someone in this forum help me out?
> > > or give me proper search query in google so that I can find a heading.
> > > or is it possible to do this?
> > > Btw, I'm using gambas from ubuntu edgy repository.
> > >
> > > --
> > > -- Yahoo!ID : ar1ef_310
> > > -- http://bayu.freelancer.web.id/
> >
> > Suppose you want to get the color of a point on a DrawingArea then:
> >
> > PUBLIC SUB DrawingArea_MouseMove()
> >         DIM c AS Integer
> >         c = DrawingArea.Grab().Image[Mouse.X, Mouse.Y]
> >
> >         ' Use color
> > END
> >
> > Note two things. (1) Here color is an integer. (2) You might want to set
> > the Tracking property of a DrawingArea to TRUE so you get mouse events
> > without a button being pressed.
> >
> > In general to get the color of a point on a Image
> >
> >         c = MyImage[X, Y]
> >
> > and to get the color of a point on a Picture:
> >
> >         c = MyPicture.Image[X, Y]
> >
> > You can extend this idea to get the color of any point on the screen:
> >
> >         c = Desktop.Grab().Image[Mouse.ScreenX, Mouse.ScreenY]
> >
> > Thanks
> >
> > 8-{)} Timothy Marshal-Nichols
> > <mailto: timothy.marshal-nichols at ...247...>
> >

This is not a good solution. 

Actually, as an X server does not provide enough control to its pixmaps (the 
images stored on the server, i.e. the Picture class), you must keep the image 
in the client side, by using the Image class.

The Image class provides an access to the pixel data. The only problem is that 
there is no real drawing method in the Image class. You must do them by hand.

This will change in the future, as in Qt 4, you have the same drawing method 
in the QImage class (Image in Gambas) and the QPixmap class (Picture in 
Gambas).

Regards,

-- 
Benoit Minisini




More information about the User mailing list