Ich versuche, die Farbe für eine Reihe von Symbolen automatisch zu ändern. Jedes Symbol hat eine weiß gefüllte Ebene und der andere Teil ist transparent. Hier ist ein Beispiel: (in diesem Fall ist es grün ist, nur um es sichtbar)Ändern Sie die Farbe der nicht transparenten Teile von PNG in Java
Ich habe versucht, die folgendes zu tun:
private static BufferedImage colorImage(BufferedImage image) {
int width = image.getWidth();
int height = image.getHeight();
for (int xx = 0; xx < width; xx++) {
for (int yy = 0; yy < height; yy++) {
Color originalColor = new Color(image.getRGB(xx, yy));
System.out.println(xx + "|" + yy + " color: " + originalColor.toString() + "alpha: "
+ originalColor.getAlpha());
if (originalColor.equals(Color.WHITE) && originalColor.getAlpha() == 255) {
image.setRGB(xx, yy, Color.BLUE.getRGB());
}
}
}
return image;
}
Das Problem, das ich ist, dass jedes Pixel haben ich bekomme den gleichen Wert hat:
32|18 color: java.awt.Color[r=255,g=255,b=255]alpha: 255
Also mein Ergebnis ist nur ein farbiges Quadrat. Wie kann ich nur die Farbe der nicht transparenten Teile ändern? Und wieso haben alle Pixel sogar den gleichen Alpha-Wert? Ich denke, das ist mein Hauptproblem: Der Alpha-Wert wird nicht richtig gelesen.
Vielen Dank für diese :) – 4ndro1d