K
kmsterrett
Hello,
I have a pixel array that contains RGB data.
This code correctly creates that png file, but it take a long time.
About 700ms.
Does anyone know of a way for me to speed this up?
I will need to write as many of 50-60 files, so I do not want my user
to wait.
Thanks in advance for any advice.
Kim
-----this is the code
WritableRaster wr;
DataBuffer db = new DataBufferUShort(pixels,720*504);
BandedSampleModel sm = new BandedSampleModel
(DataBuffer.TYPE_USHORT,720,504,3);
wr = Raster.createWritableRaster(sm,db,new Point(0,0));
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
ColorModel cm = new ComponentColorModel(cs,false,
false,Transparency.OPAQUE,DataBuffer.TYPE_USHORT);
final BufferedImage bi = new BufferedImage(cm, wr, false, null);
RenderedImage renImage = (RenderedImage)bi;
//Write generated image to a file
try {
// Save as PNG
if (renImage != null){
File filImg2d = new File(fileName + ".png");
ImageIO.write(renImage, "png", filImg2d);
}
}
catch (Exception e){
System.out.println("Error in writing image to file " +
e.getMessage() + " );
}
I have a pixel array that contains RGB data.
This code correctly creates that png file, but it take a long time.
About 700ms.
Does anyone know of a way for me to speed this up?
I will need to write as many of 50-60 files, so I do not want my user
to wait.
Thanks in advance for any advice.
Kim
-----this is the code
WritableRaster wr;
DataBuffer db = new DataBufferUShort(pixels,720*504);
BandedSampleModel sm = new BandedSampleModel
(DataBuffer.TYPE_USHORT,720,504,3);
wr = Raster.createWritableRaster(sm,db,new Point(0,0));
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
ColorModel cm = new ComponentColorModel(cs,false,
false,Transparency.OPAQUE,DataBuffer.TYPE_USHORT);
final BufferedImage bi = new BufferedImage(cm, wr, false, null);
RenderedImage renImage = (RenderedImage)bi;
//Write generated image to a file
try {
// Save as PNG
if (renImage != null){
File filImg2d = new File(fileName + ".png");
ImageIO.write(renImage, "png", filImg2d);
}
}
catch (Exception e){
System.out.println("Error in writing image to file " +
e.getMessage() + " );
}