getting pixel color information from an image

R

rfractal30

Hi

I need to get the r/g/b information from the pixels of an image.

Thanks for any advice.

Michael
 
A

Andrey Kuznetsov

I need to get the r/g/b information from the pixels of an image.what is 'image' - image file? Image? or BufferedImage?

if 'image' is Image then you need PixelGrabber
if 'image' is BufferedImage then use BufferedImage.getRGB(x, y);
if 'image' is image file then you should first load it then use one of above
methods.
 
W

Wiseguy

rfractal30 said:
Hi

I need to get the r/g/b information from the pixels of an image.

Is this what you are looking for?

int [] pv={0,0,0};
image.getData(new Rectangle(x,y,1,1)).getPixel(x,y,pv);
int pc=pv[0]<<16|pv[1]<<8|pv[2];
 
R

rfractal30

Wiseguy said:
rfractal30 said:
Hi

I need to get the r/g/b information from the pixels of an image.

Is this what you are looking for?

int [] pv={0,0,0};
image.getData(new Rectangle(x,y,1,1)).getPixel(x,y,pv);
int pc=pv[0]<<16|pv[1]<<8|pv[2];

Ok, so to get the value red it is: int pc = pv[0]<<16, to get blue: int
pc = pv[1]<<8, and to get green: int pc = pv[2];

Is that right?

If so it is just what I'm looking for. Thankyou!

Michael
 
W

Wiseguy

rfractal30 said:
rfractal30 said:
Hi

I need to get the r/g/b information from the pixels of an image.

Is this what you are looking for?

int [] pv={0,0,0};
image.getData(new Rectangle(x,y,1,1)).getPixel(x,y,pv);
int pc=pv[0]<<16|pv[1]<<8|pv[2];

Ok, so to get the value red it is: int pc = pv[0]<<16, to get blue: int
pc = pv[1]<<8, and to get green: int pc = pv[2];

Is that right?

nope.

pv[0]=red
pv[1]=green
pv[2]=blue

no bit shifts are involved unless you want one 24 bit integer that contains
all three values
 
R

rfractal30

nope.

pv[0]=red
pv[1]=green
pv[2]=blue

no bit shifts are involved unless you want one 24 bit integer that contains
all three values

Thankyou. It is a great help to me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,481
Members
44,900
Latest member
Nell636132

Latest Threads

Top