This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

scanning an image for a certain pixel color in java

 
me erum
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on a project and quiet new to java. I want to scan an image pixel by pixel for a certain color, i.e. cyan and then print the coordinates of that pixel color. The code runs, creates an output file but doesn't write anything to it. Can somebody please help me with it to find the errors. I also want to know how to read a .tiff file in java while using the same code.

Java Code:
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

These masks look wrong:

Red is in bits 16-23; green is in bits 8-15; blue is in bits 0-7. It should be:

Also, you should call close() on out at the end of the program.
 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

When is a r/g/b component ever greater than 255?
 
Campbell Ritchie
Sheriff
Pie
Posts: 47270
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:

When is a r/g/b component ever greater than 255?
When I try to explain to our undergraduates that new Color(0, 0xff00, 0) if it ever gets past the runtime will not set the colour to a brighter green than normal, but to red.

By the way: I think you ought not to use 255. I prefer to use 0xff. These numbers are demoninated in hex, so I think they ought to be assessed in hex.
 
Randall Twede
Ranch Hand
Posts: 4353
2
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for reading .tiff files try ImageIO class.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Randall Twede wrote:for reading .tiff files try ImageIO class.

He's already using the ImageIO class (to read a JPG image, in his code above). Unfortunately the JDK doesn't come with support for the TIFF format (the only formats that ImageIO can read without extra plug-ins are: JPG PNG BMP WBMP GIF) - see the API docs for the package javax.imageio.

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic