Dhruv
Dhruv

Reputation: 10703

Writable Raster to Image-png format?

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

Answers (1)

Horonchik
Horonchik

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

Related Questions