0

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.

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");
		String path = System.getProperty("user.dir");
		image = Toolkit.getDefaultToolkit().getImage(path + "/DSC00030 - Copy.jpg"); );
		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);
	}

}
1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by fareast87
0

Sorry for the duplicate threads. Dont know how to delete this thread.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.