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);
 }

}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

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

This article has been dead for over six months. Start a new discussion instead.