user572485
user572485

Reputation: 103

How can I get the RGB values of a 'TYPE_3BYTE_BGR' image?

I have an image with TYPE_3BYTE_BGR and I want to convert it to a TYPE_INT_RGB.

Though I have searched, I have not found a method to do this. I want to convert the image pixel by pixel. However, it seems that BufferedImage.getRGB(i, j) doesn't work.

How can I get the RGB values in an image of type TYPE_3BYTE_BGR?

Upvotes: 4

Views: 4027

Answers (1)

I82Much
I82Much

Reputation: 27326

I'm not sure what you mean by "getRGB(i,j) doesn't work". getRGB returns a packed int; you need to decode it.

int color = image.getRGB(i,j);
int r = (argb)&0xFF;
int g = (argb>>8)&0xFF;
int b = (argb>>16)&0xFF;
int a = (argb>>24)&0xFF;

See How to convert get.rgb(x,y) integer pixel to Color(r,g,b,a) in Java?

Upvotes: 2

Related Questions