Results 1 to 2 of 2
  1. #1
    lostsoul28 is offline Member
    Join Date
    Jan 2012
    Rep Power

    Default scanning an image for a certain pixel color

    im working on a project and quiet new to java. I want to scan an image pixel by pixel for a certain 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:
    import java.awt.Color;
    import java.awt.image.BufferedImage;
    import javax.imageio.ImageIO;
     * @author
    public class GetPixelColor {
      //int y, x, tofind, col;
    * @param args the command line arguments
    * @throws IOException  
    public static void main(String args []) throws IOException
            //read image file
         	File file1 = new File("E:\\birds.jpg");
         	//write file
         	FileWriter fstream = new FileWriter("E:\\pixellog1.txt");
         	BufferedWriter out = new BufferedWriter(fstream);
         	//color object
         	//Color cyan = new Color(0, 255, 255);
         	//find cyan pixels
         	for (int y=0; y<image1.getHeight(); y++) {
         		for (int x=0; x<image1.getWidth(); x++) {
         			//  int tofind = 0x0000FFFF;
         			//int tofind = Color.cyan.getRGB();
         			//int  col = image1.getRGB(x, y);
         			//if (col == tofind){
         			//if (cyan.equals(image1.getRGB(x, y)){
         			if ( Color.cyan.getRGB() == image1.getRGB(x, y)){
         				out.write("CyanPixel found at=" + x + "," + y);
    catch (IOException e){
    Last edited by Norm; 02-01-2012 at 01:50 PM. Reason: added code tags

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default Re: scanning an image for a certain pixel color

    but doesn't write anything to it.
    Add some debug println statements to show what the values are that the code is comparing.

Similar Threads

  1. Scanning Image Pixel by Pixel
    By the_transltr in forum Advanced Java
    Replies: 5
    Last Post: 08-28-2012, 04:01 PM
  2. Replies: 4
    Last Post: 11-08-2011, 05:04 AM
  3. Find Pixel With RGB Color?
    By TyCox94 in forum JDBC
    Replies: 8
    Last Post: 09-23-2011, 04:20 AM
  4. can you ask the color of one pixel?
    By liluma in forum New To Java
    Replies: 7
    Last Post: 09-06-2011, 07:53 PM
  5. pixel scanning too slow
    By crikey in forum Advanced Java
    Replies: 5
    Last Post: 08-21-2010, 03:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts