bubblegumsoldie
Cadet 4th Year
- Registriert
- Nov. 2012
- Beiträge
- 75
Hi!
Ich möchte ein bestimmtes Bild in ein GrayScale umwandeln, aber irgendwie stimmt etwas mit meinem Code nicht. Es zeigt einfach nur ein komplett graues bild an:
Ich möchte ein bestimmtes Bild in ein GrayScale umwandeln, aber irgendwie stimmt etwas mit meinem Code nicht. Es zeigt einfach nur ein komplett graues bild an:
Code:
public static ImageIcon greyScale(String p)
{
ImageIcon old = new ImageIcon(p);
BufferedImage Img = new BufferedImage(old.getIconWidth(), old.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
Img.getGraphics().drawImage(old.getImage(), 0,0, null);
for (int x = 0; x < Img.getWidth(); ++x)
{
for (int y = 0; y < Img.getHeight(); ++y)
{
int rgb = Img.getRGB(x, y);
int r = (rgb >> 16) & 0xFF;
int g = (rgb >> 8) & 0xFF;
int b = (rgb & 0xFF);
int gray = (r + g + b) / 3;
//System.out.println("R: " + r + " G: " + g + " B: " + b + " -> GRAY: " + gray);
Img.setRGB(x, y, gray);
}
}
return new ImageIcon(Img);
}