RGB representation of an image

M

Marcelo

Dear all,

It has been at most one hour that I look for a RGB representation of an
image. I have found BufferedImage, but this class doesn't really do what
I need.

I would like to get something like

int [][][] matrixRGB;
matrixRGB = image.getRGB_Representation();

do you have an idea where to get something like that? (a class for
exemple?? )

thanks a lot,

Marcelo
 
T

Thomas Fritsch

Marcelo said:
It has been at most one hour that I look for a RGB representation of an
image. I have found BufferedImage, but this class doesn't really do what I
need.

I would like to get something like

int [][][] matrixRGB;
matrixRGB = image.getRGB_Representation();

do you have an idea where to get something like that? (a class for
exemple?? )
To get the RGB pixels of a BufferedImage into one or more int arrays you can
use method
public int[] getRGB(int startX, int startY, int w, int h, int[] rgbArray,
int offset, int scansize)
of class BufferedImage. (see the javadoc)
For example, to get all the pixels into one large array:
BufferedImage image = ...;
int w = image.getWidth();
int h = image.getHeight();
int rgbArray[] = new int[w * h];
image.getRGB(0, 0, w, h, rgbArray, 0, w);
If instead you want to get the pixels into several subarrays, you would need
to call image.getRGB(...) several times.
 
M

Marcelo

Thanks a lot,

I have just another remaining question. So, for having a 3D matrix for
the RGB representation, I should call the function several times, but
how is the return type? Do I get first all the R values, then the G
values and at last the B values?

RRRRRRRRRRRGGGGGGGGGGGGGGBBBBBBBBBBB

or is it different ?

thanks a lot,

Marcelo


int r
 
T

Thomas Fritsch

Marcelo said:
I have just another remaining question. So, for having a 3D matrix for the
RGB representation, I should call the function several times, but how is
the return type? Do I get first all the R values, then the G values and at
last the B values?

RRRRRRRRRRRGGGGGGGGGGGGGGBBBBBBBBBBB

or is it different ?
It is different (something like ARGBARGBARGB...).
When calling BufferedImage.getRGB(..., rgbArray, ...) you get an ARGB value
in each array element of your int[] array. The first int contains the ARGB
value of the first pixel, the second int the ARGB value of the second pixel,
....
Each int contains a packed ARGB value: 8 bits for A (the opacity), 8 bits
for R, 8 bits for G, 8 bits for B.
 
R

Roedy Green

I would like to get something like

int [][][] matrixRGB;
matrixRGB = image.getRGB_Representation();

PixelGrabber is used for extracting rgb bits from rectangles in an
image.
 
Joined
Jun 18, 2009
Messages
1
Reaction score
0
I need to obtain the RGB value of a pixel but i need 3 different values i.e. The R value, G value and B value.....

i tried using BufferedImage.getRGB(int x, int y) but this returns only one value which im confused what value is this... how can the pixel intensity have 1 value ?

Please help..
 

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,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top