ellandrd
asked on
ColourClustering
getting error for getRGB() and i dont know why?
package colourclustering;
import java.awt.Image;
import java.awt.Toolkit;
import java.util.HashMap;
/**
*
* @author u0207372
*/
public class ColourClusterTester {
private HashMap hashMap;
private Image img;
/**
* Creates a new instance of ColourClusterTester
*/
public ColourClusterTester( String filename ) {
hashMap = new HashMap();
img = Toolkit.getDefaultToolkit( ).getImage ( filename );
for ( int i = 0; i < img.getWidth(null); i++ )
{
for ( int j = 0; j < img.getHeight(null); j++ )
{
int pixelFreq;
int pixelValue = img.getRGB();
hashMap.put( pixelValue, 1 );
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new ColourClusterTester( "H:\\MIOCReader\\ColourClu stering\\C olourClust ering\\src \\colourcl ustering\\ test.gif" ) ;
}
}
bascially what im trying to do is read image, get pixel value of each pixel and store value in hash map. along with the number of time that value appears but having some problems actually getting the RGB() for each pixel?
package colourclustering;
import java.awt.Image;
import java.awt.Toolkit;
import java.util.HashMap;
/**
*
* @author u0207372
*/
public class ColourClusterTester {
private HashMap hashMap;
private Image img;
/**
* Creates a new instance of ColourClusterTester
*/
public ColourClusterTester( String filename ) {
hashMap = new HashMap();
img = Toolkit.getDefaultToolkit(
for ( int i = 0; i < img.getWidth(null); i++ )
{
for ( int j = 0; j < img.getHeight(null); j++ )
{
int pixelFreq;
int pixelValue = img.getRGB();
hashMap.put( pixelValue, 1 );
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new ColourClusterTester( "H:\\MIOCReader\\ColourClu
}
}
bascially what im trying to do is read image, get pixel value of each pixel and store value in hash map. along with the number of time that value appears but having some problems actually getting the RGB() for each pixel?
ASKER
still getting red line under:
pixelValue = img.getRGB();
pixelValue = img.getRGB();
>> hashMap.put( pixelValue, 1 );
Why would you hard-code that value there unless you knew it to be unique?
Why would you hard-code that value there unless you knew it to be unique?
ASKER
because im not finished yet and have not added my if else statements.
that line shouldbe commented out but at th emoment by main concert si the getRGB() not working...
that line shouldbe commented out but at th emoment by main concert si the getRGB() not working...
>> by main concert si the getRGB() not working...
OK. My first comment should fix that
OK. My first comment should fix that
ASKER
Again to repeat myself - im still getting a red line under this line of code:
pixelValue = img.getRGB();
your first comment should but didnt fix it
pixelValue = img.getRGB();
your first comment should but didnt fix it
>>private Image img;
Change to
private BufferedImage img;
and then
pixelValue = img.getRGB(i, j);
Change to
private BufferedImage img;
and then
pixelValue = img.getRGB(i, j);
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> getRGB() is a method of Color not of Image
Well, at least the one wihtout parameters ;°)
Well, at least the one wihtout parameters ;°)
ASKER
now this line has red line under it...
img = javax.imageio.ImageIO.read (new FileInputStream( filename ));
img = javax.imageio.ImageIO.read
That's up to CEHJ, to solve that ;°)
Make sure you
import java.io.*;
import java.io.*;
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
And catch any exceptions thrown by creating the FileInputStream
>> bascially what im trying to do is read image, get pixel value of each pixel
Looks like you could use it very well
Looks like you could use it very well
Have to go offline.
Goodnight to both of you
Goodnight to both of you
ASKER
no, but by looking at the URL's contents its take me another 5 hours to add it to my code....
nobody gives straight answers on his site no more - everybody expects me to know what they know and i dont!
nobody gives straight answers on his site no more - everybody expects me to know what they know and i dont!
Your main problem was dealing with the default asynchronous loading of images
>>nobody gives straight answers on his site no more - everybody expects me to know what they know and i dont!
You've been coding Java long enough not to need spoon feeding by now ;-) You have all the pieces
You've been coding Java long enough not to need spoon feeding by now ;-) You have all the pieces
ASKER
yes but no every day, day in day out - im a web programmer and trying to learn java on the side and each time i try learning some the time between i last learned something and time i get to do some more - few wks or months later its like having to start over again!
Try to do a bit regularly. That'd happen to me if i didn't keep doing it ;-)
ASKER
>>Try to do a bit regularly
I try - but with work and other commitments it is hard to keep on top if things!
I try - but with work and other commitments it is hard to keep on top if things!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
where did this come out off? thank you!
:-)
ellandrd,
Your initial question was this:
>> getting error for getRGB() and i dont know why?
My answer was:
>> getRGB() is a method of Color not of Image
>> Well, at least the one wihtout parameters ;°)
I consider that as a comment that deserved to be awarded as an assisted answer.
Disappointed it isn't.
>> nobody gives straight answers on his site no more
Well, that WAS a rather straight answer I think.
Your initial question was this:
>> getting error for getRGB() and i dont know why?
My answer was:
>> getRGB() is a method of Color not of Image
>> Well, at least the one wihtout parameters ;°)
I consider that as a comment that deserved to be awarded as an assisted answer.
Disappointed it isn't.
>> nobody gives straight answers on his site no more
Well, that WAS a rather straight answer I think.
> Your main problem was dealing with the default asynchronous loading of images
no it wasn't
no it wasn't
ASKER
i meant by giving "straight answers" was/is actually providing some constructive / helpful advice etc etc and not the one word or one sentence answers like i got a few times.
im not saying it was all you who didnt give straight answers, but when you are trying to get some answers/ help outta people and in the process of been stressed - people who provide comments like:
img = javax.imageio.ImageIO.read (new FileInputStream( filename ));
for example, dont help especially with me struggling with Java each time i get a chance to learn it.
i didnt know how to use that code and so i didnt feel it was a straight answer and i was getting angry with the comments been made!
im not saying it was all you who didnt give straight answers, but when you are trying to get some answers/ help outta people and in the process of been stressed - people who provide comments like:
img = javax.imageio.ImageIO.read
for example, dont help especially with me struggling with Java each time i get a chance to learn it.
i didnt know how to use that code and so i didnt feel it was a straight answer and i was getting angry with the comments been made!
Curious to know why ..?
ASKER
CEHJ,
zzynx was unhappy that i didnt split the points fair enough and asked me to be fair.
If you disagree please say.
@ellandrd
zzynx was unhappy that i didnt split the points fair enough and asked me to be fair.
If you disagree please say.
@ellandrd
That's OK - just wondered
Thanx for being honest, ellandrd
img = javax.imageio.ImageIO.read