Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get Pixel and Put Pixel in Java

821 views
Skip to first unread message

Gracia Godfroid

unread,
Jan 14, 2000, 3:00:00 AM1/14/00
to
Hi,

I'm a newbie to Java and I want to know how to get/put the value
of a pixel. What object and method do I have to use?

--
Pedro Godfroid
Sevilla, Spain

Sundar

unread,
Jan 14, 2000, 3:00:00 AM1/14/00
to
You'll need to use a MouseListener.

e.g.

import java.applet.*;
import java.awt.*;
import java.awt.event.*; // for MouseListener

public PixelTest extends Applet implements MouseListener {
int x,y;
public void init() {
addMouseListener(this);
}

public void paint(Graphics g) {
g.drawLine(x,y,x,y); // draw pixel
}

// You have to include all five of these methods
public void mouseClicked(MouseEvent me) {
x=getX();
y=getY();
repaint();
}
public void mousePressed(MouseEvent me) {;}
public void mouseReleased(MouseEvent me) {;}
public void mouseEntered(MouseEvent me) {;}
public void mouseExited(MouseEvent me) {;}
}

In article <MPG.12e90c79e...@news.eintec.es>,

--
Sundar Dorai-Raj
Department of Statistics
Virginia Tech
sdor...@vt.edu


Sent via Deja.com http://www.deja.com/
Before you buy.

NT

unread,
Jan 14, 2000, 3:00:00 AM1/14/00
to
That's a whole lot of code just to get and set the value of a pixel.

Sundar <sdor...@vt.edu> wrote in message news:85nges$tn$1...@nnrp1.deja.com...


------
Posted via news://freenews.netfront.net
Complaints to ne...@netfront.net

Gracia Godfroid

unread,
Jan 14, 2000, 3:00:00 AM1/14/00
to
In article <85nges$tn$1...@nnrp1.deja.com>, sdor...@vt.edu says...

> public PixelTest extends Applet implements MouseListener {
> int x,y;
> public void init() {
> addMouseListener(this);
> }
>
> public void paint(Graphics g) {
> g.drawLine(x,y,x,y); // draw pixel
> }
>

That's a line from a point to the same point. Is there not any
simple Put Pixel method?

> // You have to include all five of these methods
> public void mouseClicked(MouseEvent me) {
> x=getX();
> y=getY();
> repaint();
> }
> public void mousePressed(MouseEvent me) {;}
> public void mouseReleased(MouseEvent me) {;}
> public void mouseEntered(MouseEvent me) {;}
> public void mouseExited(MouseEvent me) {;}
> }
>

That's not exactly what I want. I want to know the RGB value of a
particular pixel of an image, not where the mouse is.

Thanks a lot

--
Pedro Godfroid
Sevilla, Spain

PS: By the way, that's my daughter newsreader...

KRhoda

unread,
Jan 15, 2000, 3:00:00 AM1/15/00
to
Looks like code to paint with the mouse.


neuralnet

unread,
Jan 16, 2000, 3:00:00 AM1/16/00
to

Warren Schwader

unread,
Jan 19, 2000, 3:00:00 AM1/19/00
to
To get the RGB of a pixel, you'can use the PixelGrabber class. This example
gets the pixels from an image.
Here's a code snippet to get you started:

int pixels = new int[width * height];
PixelGrabber pg = new PixelGrabber(image, 0, 0, width, height, pixels, 0,
width);
try {pg.grabPixels();}
catch (InterruptedException e) {}

0 new messages