Ich bin so verloren für diesen Code, an dem ich arbeite. Ich muss ein Bild mit Graustufen machen, nur mit Java. Ich habe den Basiscode, aber ich weiß nicht, was ich einfügen soll, damit der gesamte Bildschirm nicht grau wird. Ich arbeite eifrig daran, aber ich bin verloren und habe keine Ahnung, was ich als nächstes tun soll. Die Art und Weise, wie es aktuell ist, es dauert nur ein Bild durchläuft einen Prozess, macht eine neue Version von ihm völlig gleich, aber ich muss die neue Version die graue Version davon machen. Besuchen Sie: https://ask.extension.org/uploads/question/images/attachments/000/037/087/image_300x300%2523.jpg?1406470060 Für das Baumbild, das ich benutze.Graustufenbild mit Java
import java.awt.*; //import the awt graphics package
class TrueColors //start of the class
{
TrueColors() //start of the main method
{
Picture pictureObj = new Picture("trunk.jpg");
pictureObj.explore();
int redValue = 0; int greenValue = 0; int blueValue = 0;
Pixel targetPixel = new Pixel(pictureObj, 0,0);
Color pixelColor = null;
for(int y=0; y < pictureObj.getHeight(); y++)
{
for(int x = 0; x < pictureObj.getWidth(); x++)
{
targetPixel = pictureObj.getPixel(x,y);
pixelColor = targetPixel.getColor();
redValue = pixelColor.getRed();
greenValue = pixelColor.getGreen();
blueValue = pixelColor.getBlue();
pixelColor = new Color(redValue, greenValue, blueValue);
targetPixel.setColor(pixelColor);
}//end of the inner for loop
}//end of the outer for loop
pictureObj.explore();
pictureObj.write("NewTrunk.jpg");
pictureObj.show();
}//end of main method
}//end of class
Das Problem damit ist, ich habe nicht gelernt, wie man BufferedImages verwendet. Ich arbeite an einem Kurs und dies ist eine der Aufgaben, auf die ich festhalte. –
Vielen Dank, das hat mein Problem behoben. –
(R + G + B)/3 ist eine wirklich schlechte Möglichkeit, Farben für ein Graustufenbild zu berechnen. – eldo