Hi,

I am using a code to read a grayscale image and store the pixel value in a 1D array. But the code is taking a default image(though i am providing the complete path for the image to be loaded) and the height and the width are returned as -1. Also tell me how to get the pixel value and how to store in 1D array.

my code:

import java.awt.Image;
import java.awt.*;
import java.awt.image.PixelGrabber;


class ImagetoPixel extends Frame
{   String imagePath;
    int width, height;
    Image image = null;
    PixelGrabber grabber;
    int []pixels;
    MediaTracker tracker;



    public static void main(String args[])
    {
        ImagetoPixel obj = new ImagetoPixel();
        obj.testFunction();        
    }

 void testFunction()
 {
     System.out.println("The function is to use object");
     image = Toolkit.getDefaultToolkit().getImage( "C:\\Documents and Settings\\swetaseng\\My Documents\\My Pictures\\fingerprint.jpeg" );
     if(image ==null)
     {
         System.out.println("No Image");

     }
     else
     {
     }

     System.out.println(image);
      width = image.getWidth(this);
      height = image.getHeight(this);
      grabber = new PixelGrabber(image, 0, 0, width, height, pixels, 0, width);
      System.out.println("width = " +width);
      System.out.println("height = "+ height);
 }

}

I'm also wondering the same thing about yours. Are you already got the solution? If yes, come share with us. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.