EcHo
2005-12-30, 00:29:37
Hi,
Ich habe eine Methode, die mir ein Int-Array in eine PNG-Datei schreibt - soweit so gut. Wenn das Array aber zu groß wird (z.B. 3000x3000) gibts ein:
"Exception in thread "main" java.lang.OutOfMemoryError: Java heap space"
Die methode sieht wie folgt aus:
/**
* Write an integer- array in a PNG image.
*
* @param pixelMap
* @param name
* @throws IOException
*
* Assign the integer- array and the name to this methode,
* to write it to the file name.png in the local folder.
*/
public void writePNG (int[][] pixelMap , String name) throws IOException {
int width = pixelMap[0].length;
int height = pixelMap.length;
BufferedImage bImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
bImage.setRGB(x,y, pixelMap[y][x]);
}
}
File file = new File(name + ".png");
ImageIO.write(bImage,"png", file);
}
Wo ist der Fehler und wie kann ich ihn umgehen?
Ich habe eine Methode, die mir ein Int-Array in eine PNG-Datei schreibt - soweit so gut. Wenn das Array aber zu groß wird (z.B. 3000x3000) gibts ein:
"Exception in thread "main" java.lang.OutOfMemoryError: Java heap space"
Die methode sieht wie folgt aus:
/**
* Write an integer- array in a PNG image.
*
* @param pixelMap
* @param name
* @throws IOException
*
* Assign the integer- array and the name to this methode,
* to write it to the file name.png in the local folder.
*/
public void writePNG (int[][] pixelMap , String name) throws IOException {
int width = pixelMap[0].length;
int height = pixelMap.length;
BufferedImage bImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
bImage.setRGB(x,y, pixelMap[y][x]);
}
}
File file = new File(name + ".png");
ImageIO.write(bImage,"png", file);
}
Wo ist der Fehler und wie kann ich ihn umgehen?