Reputation: 10703
I have writableRaster object. I want to save it as a png image. I learnt about Raster is that, it is a rectangular area of pixels.
Is it possible to save it as a png image? If Yes how?
Upvotes: 0
Views: 1169
Reputation: 477
You can use JAI to save images to disk, see the example: the JAI support 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");
Upvotes: 2