我正在尝试从像素数据创建 BufferedImage 。以下是我的示例代码。它适用于TYPE_BYTE_GRAY但是为TYPE_INT_RGB抛出 java.lang.ArrayIndexOutOfBoundsException
BufferedImage originalImage=<received from the caller>;
Raster raster = originalImage.getData();
SampleModel sampleModel = raster.getSampleModel();
WritableRaster writableRaster= Raster.createWritableRaster(sampleModel, new Point(0,0));
/*
* Write data to the writableRaster
*/
int imageType;
if(isColordImage)
imageType = BufferedImage.TYPE_INT_RGB;
else
imageType = BufferedImage.TYPE_BYTE_GRAY;
BufferedImage newImage = new BufferedImage(imageWidth, imageHeight, imageType);
newImage.setData(writableRaster);
我哪里错了?提前谢谢。