Exchange between color format in java

1

In a program I am extracting the color of a certain bit of an image with the method:

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;

BufferedImage image = null;

image = ImageIO.read(new File(dir));

for(int i=0;i<800;i++){
    for(int j=0;j<800;j++){
        int biomeColour = image.getRGB(i, j);

The problem is that the image.getRGB () returns the color in the 8-bit RGBA format according to the java api: Api page . As would be done to change from this format to the RGB format

    
asked by Pasblo 11.03.2018 в 15:25
source

1 answer

1

I have found a way to do it, for those who are interested:

import java.awt.image.DirectColorModel; 

DirectColorModel = tranformMatrix = new DirectColorModel(32, 0x00ff0000, 0x0000ff00, 0x000000ff); 

float red = tranformMatrix.getRed(biomeColour); 
float green = tranformMatrix.getGreen(biomeColour); 
float blue = tranformMatrix.getBlue(biomeColour);
    
answered by 11.03.2018 / 20:02
source