Problem mit subImage

Status
Nicht offen für weitere Antworten.

Liathne

Mitglied
Hallöchen zusammen,

ich stehe mal wieder vor einem Problem, ich möchte ein eingelesenes Bild, welches garantiert quadratisch ist, in 16 gleich große Subimages teilen.

Mein Ansatz ist folgender:

Code:
   public static void cropLvlOne(BufferedImage img, File file, String output) throws Exception{
        BufferedImage bi;
        int width = img.getWidth();
        int heigth = img.getHeight();
        for (int x = 0; x < 4; x++) {
            for (int y = 3; y >= 0; y--) {
                bi =  img.getSubimage(x * (img.getWidth() / 4), y * (img.getHeight() / 4), (x + 1) * (img.getWidth() / 4), (y + 1) * (img.getHeight() / 4));
                String  filename = file.getName();
                filename = filename.substring(0, filename.length()-4);
                filename += "_00_"+x+(3-y);
                String outputdir = output+File.separatorChar+filename+".bmp";
                ImageIO.write(bi, "bmp", new File( outputdir )  );
            }
        }
    }

Jedoch funktioniert es nicht, und ich erhalte bei der Ausführung eine java.awt.image.RasterFormatException: (y + height) is outside of Raster

Kann sich das jemand erklären?

Vielen Dank für Eure Hilfe.

Liathne
 
Die Letzten parameter von getSubImage sind die Breite und Höhe des Subimages, und nicht die "eck-Koordinaten".
Mit
img.getHeight() / 4
statt
(y + 1) * (img.getHeight() / 4)
könnte es gehen
 
Status
Nicht offen für weitere Antworten.

Zurück
Oben