Reputation: 486
I have a small problem. I have a BufferedImage which has pixels that have an RGB value. This code is used to create an RGB value from de R, G, B, A values.
private int getRGB(int r, int g, int b, int a){
return (a << 24) | (r << 16) | (g << 8) | b;
}
The first question is, how can i get the R, G, B, A values from a Pixel, because the pixel RGB will return the number that is generated by the code above.
And if I have those values, can I put 2 pixels on top of each other so it calculates the new values or do I have to do that by manual? With automatic calculation you can think of Java 2D when you put 2 transport things on top it will merge the colors.
Thank you very much.
Upvotes: 2
Views: 257
Reputation: 140319
The first question is, how can i get the R, G, B, A values from a Pixel, because the pixel RGB will return the number that is generated by the code above.
You can reverse the process as follows:
int a = (argb >> 24) & 0xFF;
int r = (argb >> 16) & 0xFF;
int g = (argb >> 8) & 0xFF;
int b = (argb >> 0) & 0xFF;
And if I have those values, can I put 2 pixels on top of each other so it calculates the new values or do I have to do that by manual? With automatic calculation you can think of Java 2D when you put 2 transport things on top it will merge the colors.
You will need to do this manually (or invoking a utility method per-pixel), since you need to decide how to composite the colors, e.g. you could use the maximum, sum, mean etc pixel value.
Upvotes: 2