Computing.Net > Forums > Programming > java programming

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

java programming

Reply to Message Icon

Name: tony
Date: November 10, 2003 at 10:45:16 Pacific
OS: xp
CPU/Ram: 256
Comment:

i have read in a file using the getimage method but now wish to store each pixels RGB value in an array, i have tried using PixelGrabber and grabPixels but am getting errors with these methods. Can anyone see where i'm going wrong or suggest another method for my problem?
help would be appreciated!
tony

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

public class LoadImage extends Frame {
private Image image;

public LoadImage(String fileName) {

int w, h;
image = Toolkit.getDefaultToolkit().getImage(fileName);
MediaTracker mediaTracker = new MediaTracker(this);
mediaTracker.addImage(image, 0);
try
{
mediaTracker.waitForID(0);
}
catch (InterruptedException ie)
{
System.err.println(ie);
System.exit(1);
}

int width = image.getWidth(null);
int height = image.getHeight(null);


//////////////////////////////////////
// errors occuring in this block-->
int[] pixels = new int[width * height];
PixelGrabber myPixelGrabber = new PixelGrabber(image, 0, 0, width, height, pixels, 0, width);
myPixelGrabber.grabPixels();
////////////////////////////////////////////////
}
public static void main(String[] args) {
new LoadImage(args[0]);
}
}



Sponsored Link
Ads by Google

Response Number 1
Name: Daemon Rose
Date: November 10, 2003 at 13:05:24 Pacific
Reply:

Okay I haven't done Java in like ages, but I think the problem may be above the area your looking at, when you get the height and width you use:
int width = image.getWidth(null);
but I believe this should be:
int width = image.getWidth(this);
(for both of them of course).
Check our this guys example of the code (link: http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20336901.html
He's doing the same thing (it right around halfway down the page, just search for pixelgrabber). Otherwise you could simply print out the width and height before you use them and make sure they are not zero.


0

Response Number 2
Name: tony
Date: November 11, 2003 at 05:06:12 Pacific
Reply:

thanks for your help, the link was great help...i was just stupid and forgot to import one of the correct libraries...
: )


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


dynamic allocation VB.Net and Graphing Help?



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: java programming

Please help with java program. www.computing.net/answers/programming/please-help-with-java-program/14834.html

help on java programming www.computing.net/answers/programming/help-on-java-programming/3347.html

Read MS Access using Java program www.computing.net/answers/programming/read-ms-access-using-java-program/3986.html