Witam,
Napisałem taki oto kod, który obraca obrazek:
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.io.*;
import java.lang.Math;
import javax.imageio.*;
public class Temat6{
public Temat6() {
}
public static void main(String[] args) {
try {
DataInput datainput = new DataInputStream(System.in);
BufferedImage bimg;
//odczyt z pliku
System.out.println("Podaj źródło obrazu: ");
bimg = ImageIO.read(new File(datainput.readLine()));
System.out.println("Podaj gdzie zapisać obraz po obróceniu: ");
File saveas = new File(datainput.readLine());
System.out.println("Kąt o który obrócić[stopnie]: ");
//konwersja stringa do inta
int degress = Integer.parseInt(datainput.readLine());
int w = bimg.getWidth();
int h = bimg.getHeight();
//przeliczanie stopni na radiany, zebezpieczenie przed ujemnymi wartościami i zwielokrotnionym 2pi
degress = degress % 360;
degress = degress + 360;
degress = degress % 360;
double radians = Math.toRadians(degress);
//obrot
AffineTransform at = new AffineTransform();
at.rotate(radians, w / 2, h / 2);
//zeby zapobiec obcieciu rogów
double x, y;
if (degress <= 90 ) {
x = -at.transform(new Point2D.Double(0, h), null).getX();
y = -at.transform(new Point2D.Double(0, 0), null).getY();
}
else if (degress <= 180 ) {
x = -at.transform(new Point2D.Double(w, h), null).getX();
y = -at.transform(new Point2D.Double(0, h), null).getY();
}
else if (degress <= 270 ) {
x = -at.transform(new Point2D.Double(w, 0), null).getX();
y = -at.transform(new Point2D.Double(w, h), null).getY();
}
else {
x = -at.transform(new Point2D.Double(0, 0), null).getX();
y = -at.transform(new Point2D.Double(w, 0), null).getY();
}
AffineTransform at2 = new AffineTransform();
at2.translate(x, y);
at.preConcatenate(at2);
//zastosowanie i zapisanie
BufferedImageOp bio = new AffineTransformOp(at, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
bimg = bio.filter(bimg, null);
//zapisanie do pliku w tym samym formacie
String extension = saveas.getName().substring(saveas.getName().indexOf('.') + 1);
ImageIO.write(bimg, extension, saveas);
System.out.println("Obrót wykonany pomyślnie.");
System.out.print("Wyjście z programu.");
} catch (IOException except) {
System.out.println("Wystąpił błąd. Następuje zakończenie programu.");
}
}
}
Jak sprawić, żeby kolor tych rogów powstałych po obróceniu był inny niż czarny(domyślny)?
Pozdrawiam