Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

how to get Color name from a specific pixel ??

Sun Jun 10, 2007 9:01 pm

hello

i've the code :

Code:
class A{
    public static void main(String[] args){
        try {
            BufferedImage bi=ImageIO.read(new File("C:\\a.gif"));
     int a=bi.getRGB(20,20);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
       
    }
}


i don't know how to get the color name , i can create new Object from color by Color(r,b,g) but i want the name .
and it seem hard because i must do bit twice (&00xFF)

is there any alternative ways to get Color name from specific pixel ?



Re: how to get Color name from a specific pixel ??

Sun Jun 10, 2007 9:38 pm

Hi ,Xline
Code:
int a=bi.getRGB(20,20);

now you can use the value of a to get the R ,G,B Components using binary Shift like Bellow

Code:
               int r = (rgb >> 16) & 0xff;
                    int g = (rgb >> 8) & 0xff;
                    int b = (rgb >> 0) & 0xff;

then you can use it in new Color(R,G,B);

and also you can get it Back to Original Value
Code:
    rgb= (rgb & 0xff000000) | (r << 16) | (g << 8) | (b << 0);



I Hope that helped you

Post a reply
  Related Posts  to : how to get Color name from a specific pixel ??
 Specific Colors for Specific Forum     -  
 ban visitor from a specific IP-address     -  
 Reading a Specific Character in php     -  
 ordered list from specific number     -  
 Rotate Image with specific angle     -  
 Check the websites hosted at a specific IP     -  
 Clear specific form fields using JQuery     -  
 Slide automatically-specific speed to a determined position     -  
 Color and CSS     -  
 change background color with RGB     -