New topic: Proper way to get pixel color of window/canvas/etc (not pic)
<http://forums.realsoftware.com/viewtopic.php?t=44776> Page 1 of 1 [ 8 posts ] Previous topic | Next topic Author Message jlawrence Post subject: Proper way to get pixel color of window/canvas/etc (not pic)Posted: Thu Jul 19, 2012 2:20 pm Joined: Thu Dec 16, 2010 1:22 pm Posts: 159 Since we are deprecating Graphics in favor of Paint, I don't know how to do this. I used to use self.graphics.pixel or me.graphics.pixel, but it complains when I do a check. The language reference says to use Dim c as Color c = Canvas1.Graphics.Pixel(10, 10) and Canvas1.Graphics.Pixel(10, 10) = RGB(100, 105, 225) for getting and setting a pixel color, but guess what? Those also throw a warning. I tried System.pixel as well, since I only need to Get the color, and the language reference even says (incorrectly): Quote:The following example is in the MouseDown event. It gets the color of the pixel the mouse is on. Dim c As Color c = System.Pixel(x, y) but guess what? That doesn't work as written. The MouseDown event passes x,y relative to the window, but System.Pixel(x,y) is the entire screen. So you have to take into account the Window Position, the Title Bar, the Menu Bar, the Window Border etc... If the pixel in question is in a picture, I understand I would use RGBSurface.pixel, right? But this isn't in a picture, so what am I missing? What is the correct way to read a pixel color in a window/canvas/etc without using Graphics? Thanks Top charonn0 Post subject: Re: Proper way to get pixel color of window/canvas/etc (notPosted: Thu Jul 19, 2012 2:54 pm Joined: Mon Apr 02, 2007 2:08 am Posts: 848 Location: San Francisco, CA, USA Try Dim c as Color c = System.Pixel(System.MouseX, System.MouseY) Also, I don't think that warning is applicable if you are only reading a Pixel value. _________________ Boredom Software Top jlawrence Post subject: Re: Proper way to get pixel color of window/canvas/etc (not Posted: Thu Jul 19, 2012 4:09 pm Joined: Thu Dec 16, 2010 1:22 pm Posts: 159 Your code certainly solves the language reference error for System.Pixel, however, (and I know I didn't clarify in my original post), I have a need to get the pixel color of a certain section, without necessarily having the mouse hover over it. Other ideas? And as you say I can just ignore the warning that the IDE throws when using Dim c as Color c = Canvas1.Graphics.Pixel(10, 10) ?? Can someone at RS confirm that this is ok, and it won't blow up when Graphics go from deprecated to nonexistent? Or someone else have an alternative? Thanks again! Top charonn0 Post subject: Re: Proper way to get pixel color of window/canvas/etc (notPosted: Thu Jul 19, 2012 4:12 pm Joined: Mon Apr 02, 2007 2:08 am Posts: 848 Location: San Francisco, CA, USA jlawrence wrote: I have a need to get the pixel color of a certain section, without necessarily having the mouse hover over it. Other ideas? Do you know the X,Y coordinates you want? If so, just use those instead of MouseX and MouseY. _________________ Boredom Software Top jlawrence Post subject: Re: Proper way to get pixel color of window/canvas/etc (notPosted: Thu Jul 19, 2012 4:35 pm Joined: Thu Dec 16, 2010 1:22 pm Posts: 159 Quote:Do you know the X,Y coordinates you want? If so, just use those instead of MouseX and MouseY. Well, I do, but like I said, it's difficult, if not impossible to get the system.pixel from the coordinates of something in a window isn't it? Title bar, menu bar, window border, window position all have to be taken into account (probably also the dock position and size) Ugh. I just want to use .Graphics instead, that was so much easier. Top charonn0 Post subject: Re: Proper way to get pixel color of window/canvas/etc (notPosted: Thu Jul 19, 2012 4:58 pm Joined: Mon Apr 02, 2007 2:08 am Posts: 848 Location: San Francisco, CA, USA jlawrence wrote:Ugh. I just want to use .Graphics instead, that was so much easier. I still think it's an erroneous warning in this case. Hopefully someone can confirm that. _________________ Boredom Software Top mallen Post subject: Re: Proper way to get pixel color of window/canvas/etc (not Posted: Thu Jul 19, 2012 5:14 pm Joined: Mon Mar 01, 2010 11:59 pm Posts: 41 Location: Silicon Valley The other problem with System.Pixel is that it is no longer support on OS X 10.7 and above. _________________ mallen iMac 3.4 GHz Intel Core i7, OS X 10.7.4; RS 2011r4.3 "Sometimes you're the windshield, Sometimes you're the bug." â Mark Knopfler, The Bug, 1991 Top charonn0 Post subject: Re: Proper way to get pixel color of window/canvas/etc (notPosted: Thu Jul 19, 2012 5:27 pm Joined: Mon Apr 02, 2007 2:08 am Posts: 848 Location: San Francisco, CA, USA mallen wrote:The other problem with System.Pixel is that it is no longer support on OS X 10.7 and above. Seriously? _________________ Boredom Software Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 8 posts ]
-- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
