Results 1 to 9 of 9
- 11-24-2008, 07:18 PM #1
Member
- Join Date
- Nov 2008
- Posts
- 2
- Rep Power
- 0
Been stuck for days! any help would be appriciated...
hey...
Ok this is really starting to annoy me so please please help!
I am trying to create a program which will take in a colour picture, turn it into an array of pixels covert those pixels into greyscale and put array back together again to make a greyscale copy of the first image.
The code below is of the section i am stuck on. Basically i want to use color(int rgb) constructor to make a new object which i can pass my color pixel array into. i then want to create 3 new ints and make them equal to the red, green and blue values of my new Color.
for (int i = 0; i < (width*height); i++){
Color c = new Color(pixels*);
int red = getRed();
int green = getGreen();
int Blue = getBlue();
}
*the array of color pixels.
Im new so please be gentle!
cheers
- 11-25-2008, 01:21 PM #2
Study the java image io classes, or emulate an image with a two dimensional array of a placeholder class you write yourself.
Bring your lunch, your gonna be awhile before you can do Color.getRed() and so on.
Graphics is rather advanced. I suggest ( if you need gentle ) move to some other simplified program such as hello world or develope simple array skills before working on what you have here.Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 11-25-2008, 01:42 PM #3
Member
- Join Date
- Nov 2008
- Posts
- 2
- Rep Power
- 0
thanks for the reply... done a little more work on it now got it to compile but instead of a greyscale image being returned i get a black image....
my code is as follows:
class SaveGreyMenuListnr implements ActionListener {
private ImagePanel panel = null;
SaveGreyMenuListnr (ImagePanel pn) {
panel = pn;
}
public void actionPerformed (ActionEvent ae) {
Image displayed = panel.getDisplayImage();
int width = displayed.getWidth(panel);
int height = displayed.getHeight(panel);
int pixels[] = new int[width*height];
PixelGrabber pg = new PixelGrabber(displayed, 0, height, width, height, pixels, 0, width);
try{
pg.grabPixels();
} catch (InterruptedException e) {
System.err.println("interrupted waiting for pixels");
}
for (int i = 0; i < (width*height); i++){
Color myColor = new Color(pixels[i]);
int Red = myColor.getRed();
int Green = myColor.getGreen();
int Blue = myColor.getBlue();
double temp = 0.56 * (double)Green + 0.33 *(double) Red + 0.11 *(double) Blue;
myColor = new Color((int)temp,(int)temp,(int)temp);
int compressedInt = myColor.getRGB();
pixels[i] = compressedInt;
}
Image image = panel.getToolkit().createImage(new MemoryImageSource(width,height,pixels,0,width));
panel.setDisplayImage(image);
panel.repaint();
}
}
All i can think of is that when im using the getRed,getGreen and getBlue methods they are returning 0 values.
I tested this by putting a System.out.println(Red); and it just returned a large number of 0's...
Im sure its something easy ive missed if anyone has any bright ideas i would be very grateful!
- 01-15-2009, 03:43 AM #4
Where are you getting the image from? Why is there ActionListener / ActionPerformed?
Code is a little messy, but that is common on beginner code, what we need to do here is grasp where the image comes from, pass that to PixelGrabber, no?
I want to do something like this in my own program, such blunderous code does not bother me - what we need to establish first is where the graphic is coming from......Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 01-06-2011, 12:11 PM #5
Member
- Join Date
- Jan 2011
- Posts
- 11
- Rep Power
- 0
hi, im referring to ur code:
int pixels[] = new int[width*height];
.
.
for (int i = 0; i < (width*height); i++){
Color myColor = new Color(pixels[i]);
.
.
.
myColor = new Color((int)temp,(int)temp,(int)temp);
int compressedInt = myColor.getRGB();
pixels[i] = compressedInt; }
can u pls explain to me wat does the above codes for? thx in advance.
}
- 01-06-2011, 12:14 PM #6
Member
- Join Date
- Jan 2011
- Posts
- 11
- Rep Power
- 0
hi, im referring to ur code:
int pixels[] = new int[width*height];
.
.
for (int i = 0; i < (width*height); i++){
Color myColor = new Color(pixels[i]);
.
.
.
myColor = new Color((int)temp,(int)temp,(int)temp);
int compressedInt = myColor.getRGB();
pixels[i] = compressedInt; }
can u pls explain to me wat does the above codes for? thx in advance.
}
- 01-06-2011, 12:25 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
- 01-06-2011, 12:28 PM #8
Member
- Join Date
- Jan 2011
- Posts
- 11
- Rep Power
- 0
lol i know. i was juz replying here coz i dunno wanna make a double post. but i posted mine anyway, would u pls be kind enogh to help me sir? how to count frequency of the color? ur help is appreciated.
-
Similar Threads
-
really stuck now..
By shongo in forum Advanced JavaReplies: 2Last Post: 11-09-2008, 02:56 AM -
[SOLVED] Stuck in need of help!
By Zombie_Leg! in forum New To JavaReplies: 12Last Post: 09-23-2008, 03:18 AM -
Stuck in need of help!
By Zombie_Leg! in forum New To JavaReplies: 1Last Post: 09-23-2008, 02:22 AM -
No fo days between two dates
By Java Tip in forum Java TipReplies: 0Last Post: 01-28-2008, 09:06 AM -
I am completely stuck
By jpnym15 in forum New To JavaReplies: 2Last Post: 11-14-2007, 06:40 PM


LinkBack URL
About LinkBacks


Bookmarks