2012-03-16 48 views
0

我有writeableRaster對象。我想把它保存爲一個PNG圖像。我學到了Raster,它是一個矩形區域的像素。可寫入光柵到Image-png格式?

是否可以將其保存爲PNG圖像?如果是如何?

回答

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");