1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| private void setImages()
{
hImg = new BufferedImage((int)(monImage.getWidth()),(int)( monImage.getHeight()), monImage.getType());
sImg = new BufferedImage((int)(monImage.getWidth()),(int)( monImage.getHeight()), monImage.getType());
lImg = new BufferedImage((int)(monImage.getWidth()),(int)( monImage.getHeight()), monImage.getType());
int width = monImage.getWidth();
int height = monImage.getHeight();
for(int i=0; i<height; i++){
for(int j=0; j<width; j++){
int p = monImage.getRGB(j, i);
float[] hsbvals = new float[3];
Color.RGBtoHSB((p>>16)&0xff, (p>>8)&0xff, p&0xff, hsbvals);
int h = (int)(hsbvals[0]*255);
int s = (int)(hsbvals[1]*255);
int l = (int)(hsbvals[2]*255);
hImg.setRGB(j,i,new Color(h,h,h).getRGB());
sImg.setRGB(j,i,new Color(s,s,s).getRGB());
lImg.setRGB(j,i,new Color(l,l,l).getRGB());
}
}
}
protected void afficheImageLuminance(){
monImage = lImg;
repaint();
}
protected void afficheImageSaturation(){
monImage = sImg;
repaint();
}
public void afficheimageteinte(){
monImage = hImg;
repaint();
}
public void toColor(){
int width = monImage.getWidth();
int height = monImage.getHeight();
for(int i=0; i<height; i++){
for(int j=0; j<width; j++){
float h = ((hImg.getRGB(j, i)>>16)&0xff) /255.0f;
float s = ((sImg.getRGB(j, i)>>16)&0xff) /255.0f;
float l = ((lImg.getRGB(j, i)>>16)&0xff) /255.0f;
monImage.setRGB(j,i,Color.getHSBColor(h, s,l).getRGB());
}
}
repaint();
} |