Results 1 to 4 of 4
  1. #1
    jdeep is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default reading pixel values

    hi, m new to java, pls help me!
    i need to get pixel values from an image, m getting "file not found" msg when i run this code....where should i place the image file??


    Java Code:
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;
     
    public class Pixels {
     
        public static void main(String args[]) {
          
            BufferedImage image = readImage("C:/a/a.jpg");
     
          
            printAllARGBDetails(image);
        }
     
        public static void printAllARGBDetails(BufferedImage image) {
            int width = image.getWidth();
            int height = image.getHeight();
            System.out.println("Image Dimension: Height-" + height + ", Width-"
                    + width);
            System.out.println("Total Pixels: " + (height * width));
            for (int i = 0; i < width; i++) {
                for (int j = 0; j < height; j++) {
     
                    int pixel = image.getRGB(i, j);
                    System.out.println("Pixel Location(" + i + "," + j + ")- ["
                            + getARGBPixelData(pixel) + "]");
                }
            }
        }
        public static String getARGBPixelData(int pixel) {
            String pixelARGBData = "";
           
            int alpha = (pixel >> 24) & 0x000000FF;
     
            int red = (pixel >> 16) & 0x000000FF;
     
           
            int green = (pixel >>8 ) & 0x000000FF;
    
            int blue = (pixel) & 0x000000FF;
     
            pixelARGBData = "Alpha: " + alpha + ", " + "Red: " + red + ", "
                    + "Green: " + green + ", " + "Blue: " + blue;
     
            return pixelARGBData;
        }
     
        public static BufferedImage readImage(String fileLocation) {
            BufferedImage img = null;
            try {
                img = ImageIO.read(new File(fileLocation));
            } catch (IOException e) {
                e.printStackTrace();
            }
            return img;
        }
     
    
    }

  2. #2
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Default Re: reading pixel values

    It looks for a image in C:/a/a.jpg

  3. #3
    jdeep is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default Re: reading pixel values

    but its showing "file not found".....is dis code correct or not?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: reading pixel values

    For debugging:
    Move the creation of the File class object out of the read() method call, create a File object and print out the File class's method that returns the absolute path to the file.
    Also call the File class's exists() method to see if the program can see the file.

Similar Threads

  1. reading pixel values from images
    By utkarsh 1 in forum Java 2D
    Replies: 18
    Last Post: 12-22-2011, 10:02 PM
  2. Replies: 8
    Last Post: 05-18-2011, 03:01 PM
  3. How to read the pixel values of a jpg binary image
    By carindia in forum New To Java
    Replies: 2
    Last Post: 09-17-2010, 06:19 PM
  4. problem with pixel values of an image
    By SreerajSarma in forum New To Java
    Replies: 6
    Last Post: 03-06-2010, 03:47 PM
  5. Replies: 14
    Last Post: 04-10-2009, 08:46 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
  •