The moose likes Java in General and the fly likes scanning an image for a certain pixel color in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "scanning an image for a certain pixel color in java" Watch "scanning an image for a certain pixel color in java" New topic
Author

scanning an image for a certain pixel color in java

me erum
Greenhorn

Joined: Feb 05, 2012
Posts: 2
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

Joined: Aug 16, 2005
Posts: 14347
    
  22

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5


When is a r/g/b component ever greater than 255?


luck, db
There are no new questions, but there may be new answers.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39834
    
  28
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

Joined: Oct 21, 2000
Posts: 4347
    
    2

for reading .tiff files try ImageIO class.


SCJP
Visit my download page
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14347
    
  22

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
 
subject: scanning an image for a certain pixel color in java