Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / February 2004

Tip: Looking for answers? Try searching our database.

value of pixels from a jpanel

Thread view: 
JSA - 16 Feb 2004 21:56 GMT
hi there,
im trying to read the color of a pixel in a jpanel. the application is
like a paint program; the user can draw using the mouse anywhere on a
jpanel. what i'd like to do is to read the color value at each point of
the panel to determine which places have been painted. is there any
direct way by using jpanels? or even awt panels?

thanks in advance
Ryan Stewart - 17 Feb 2004 03:55 GMT
> hi there,
> im trying to read the color of a pixel in a jpanel. the application is
[quoted text clipped - 4 lines]
>
> thanks in advance

If you're doing your own double buffering, why not just use your back
buffer? If you're not, then... not that I know of. You could kind of halfway
double buffer: create a BufferedImage and draw to it whenever you draw to
the JPanel. Of course, you're doing twice the work then. Might as well fully
implement your own double buffering and cut out the panel painting.
ak - 17 Feb 2004 08:15 GMT
> im trying to read the color of a pixel in a jpanel. the application is
> like a paint program; the user can draw using the mouse anywhere on a
> jpanel. what i'd like to do is to read the color value at each point of
> the panel to determine which places have been painted. is there any
> direct way by using jpanels? or even awt panels?

you _must_ to draw first to BufferedImage, this image you draw then to
panel.
without using such image the content gets lost for example after you drag
another window over you panel.
to determine pixel color under mouse pointer you should add
MouseMotionListener to your (j)panel:
at every mouseMoved event you get first the mouse coords and then get pixel
at this coords in your BufferedImage.

BufferedImage bi;
JPanel panel;

panel.addMouseMotionListener(new MouseMotionAdapter() {
   public void mouseMoved(MouseEvent e) {
       Point p = e.getPoint();
       int rgb = bi.getRGB(p.x, p.y);
   }
}

--

____________

http://reader.imagero.com the best java image reader.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
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



©2008 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.