Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: pick a color on a picture

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    5
    My Mood
    Amused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default pick a color on a picture

    i am coding a program via java swing
    i have a panel and i hold a pic (.jpg) in this panel
    when i click on this panel i can get rgb values of this pixel
    i wanna pick this color on this picture.i mean i just want to see this color, the other colors arent desired for me
    which way i must choose?

    thanks for your interest


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: pick a color on a picture

    What have you tried? Where are you stuck?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Aug 2013
    Posts
    5
    My Mood
    Amused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: pick a color on a picture

    actually i didnt try a lot approaches..i tried to use transparency but it didnt work or i couldnt. i dont know which approach must be followed. i need an idea,like this "you can try this one"

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: pick a color on a picture

    You haven't really given us enough information for us to suggest anything. What exactly do you mean by "pick this color"? Do you want to select parts of an image with a similar color? The exact color? Do you want to eliminate anything with that color, or with any other color? Do you want to copy that color to the clipboard? Something else?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    Aug 2013
    Posts
    5
    My Mood
    Amused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: pick a color on a picture

    I want to eliminate any other colors in this pic. For example we picked black, i want only black pixels must be drawn for this pic on the panel. The other pixels arent necessary for me.

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: pick a color on a picture

    Check out the API for BufferedImage. That class has a method getRGB() that returns the rgb values of every pixel in the image. Iterate over that, and only copy over pixel values that match what you want into a new BufferedImage, and draw the new BufferedImage instead.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. The Following User Says Thank You to KevinWorkman For This Useful Post:

    trenci.jack (August 13th, 2013)

  8. #7
    Junior Member
    Join Date
    Aug 2013
    Posts
    5
    My Mood
    Amused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: pick a color on a picture

    it sounds good, i will try it. There is an inconsistency about getRGB(), i couldnt use it. I used robot.getPixelColor()

  9. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: pick a color on a picture

    Why couldn't you use it? The Robot class will grab pixels from the screen, but that doesn't help you with modifying them or copying them to a new image. Why not just get it directly from the BufferedImage?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  10. #9
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: pick a color on a picture

    Quote Originally Posted by trenci.jack View Post
    There is an inconsistency about getRGB(), i couldnt use it.
    You are aware that getRGB() returns an integer pixel in the default RGB color model (TYPE_INT_ARGB) which includes the alpha, not just RGB

  11. #10
    Junior Member
    Join Date
    Aug 2013
    Posts
    5
    My Mood
    Amused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: pick a color on a picture

    ok i will try to get it directly from the BufferedImage, i didnt know that the robot class grabs pixels from the screen, but that doesn't help with modifying them or copying them to a new image

    --- Update ---

    yeah i know getRGB() returns an integer pixel which includes the alpha

Similar Threads

  1. HELP - placing picture on top of another picture in Java - JLayerPane
    By smasm in forum What's Wrong With My Code?
    Replies: 39
    Last Post: April 27th, 2012, 07:16 PM
  2. [SOLVED] Need help with Pick A Card Program Please
    By gcjava in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 22nd, 2012, 04:46 AM
  3. Converting a picture made up of 0s and 1s into a colored picture??
    By Kranti1992 in forum Java Theory & Questions
    Replies: 10
    Last Post: November 21st, 2011, 06:25 PM
  4. text color changer based on words/ word classification by color
    By knoxy5467 in forum Java Theory & Questions
    Replies: 25
    Last Post: June 15th, 2011, 07:52 AM

Tags for this Thread