可写入的Raster到Image-png格式?

时间:2012-03-16 04:59:54

标签: java image-processing java-ee-6

我有writableRaster对象。我想将它保存为png图像。 我了解到Raster就是这样,它是一个像素的矩形区域。

是否可以将其另存为png图像?如果是,如何?

1 个答案:

答案 0 :(得分:2)

您可以使用JAI将图像保存到磁盘,请参阅示例: JAI支持tiff,jpeg,png ......

SampleModel sampleModel =
  RasterFactory.createBandedSampleModel(DataBuffer.TYPE_FLOAT,  width,height,1);
  // Create a compatible ColorModel.
  ColorModel colorModel = PlanarImage.createColorModel(sampleModel);

 Raster raster = RasterFactory.createWritableRaster(sampleModel,dbuffer, new Point(0,0));
  // Create a TiledImage using the float SampleModel.
  TiledImage tiledImage = new TiledImage(0,0,width,height,0,0,
  sampleModel,colorModel);
  // Set the data of the tiled image to be the raster.
  tiledImage.setData(raster);
  // Save the image on a file.
  JAI.create("filestore",tiledImage,"floatpattern.tif","TIFF");