由于我是使用JAI进行TIFF处理的新手,我正在尝试使用浮动数据创建6000 * 6000的RGB TIFF图像。实际上代码适用于5000 * 5000图像但是当我增加大小时,我在第tiledImage.setData(pattern);
行得到了Java堆空间错误
请告诉我是否使用平铺概念创建RGB /多波段RIFF图像的正确方法。或者有什么方法可以创建吗?
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.awt.image.DataBufferFloat.<init>(DataBufferFloat.java:53)
at java.awt.image.ComponentSampleModel.createDataBuffer(ComponentSampleModel.java:409)
at javax.media.jai.RecyclingTileFactory.createTile(RecyclingTileFactory.java:397)
at javax.media.jai.PlanarImage.createWritableRaster(PlanarImage.java:1995)
at javax.media.jai.TiledImage.createTile(TiledImage.java:998)
at javax.media.jai.TiledImage.getWritableTile(TiledImage.java:1118)
at javax.media.jai.TiledImage.setData(TiledImage.java:1241)
at javaapplication17.Test3.main(Test3.java:69)
Java Result: 1
public class Test3 {
public static void main(String a[]) {
int imageHeight = 6000;
int imageWidth = 6000;
WritableRaster raster;
int[] bandOffsets = new int[3];
bandOffsets[0] = 2;
bandOffsets[1] = 1;
bandOffsets[2] = 0;
PixelInterleavedSampleModel sm = new PixelInterleavedSampleModel(DataBuffer.TYPE_FLOAT, imageWidth, imageHeight, 3, 3 * 6000, bandOffsets);
// Origin is 0,0.
WritableRaster pattern = Raster.createWritableRaster(sm, new Point(0, 0));
float[] bandValues = new float[3];
bandValues[0] = 90;
bandValues[1] = 45;
bandValues[2] = 45;
// Set values for the pattern raster.
for (int y = 0; y < pattern.getHeight(); y++) {
for (int x = 0; x < pattern.getWidth(); x++) {
pattern.setPixel(x, y, bandValues);
bandValues[1] = (bandValues[1] + 1) % 255;
bandValues[2] = (bandValues[2] + 1) % 255;
}
}
ColorModel colorModel = PlanarImage.createColorModel(sm);
// Create a TiledImage using the SampleModel.
TiledImage tiledImage = new TiledImage(0, 0, imageWidth, imageHeight, 0, 0, sm, colorModel);
// Set the data of the tiled image to be the raster.
tiledImage.setData(pattern);
// Save the image on a file.
JAI.create("filestore", tiledImage, "rgbpattern_test4.tif", "TIFF");
}
}
答案 0 :(得分:2)
简单的解决方案是使用-Xmx选项增加堆大小。