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() + " );
}
Andrew Thompson - 23 Feb 2007 15:18 GMT
..
> Does anyone know of a way for me to speed this up?
Post an SSCCE?
> I will need to write as many of 50-60 files ..
Where is the loop in your code?
Andrew T.
kmsterrett - 23 Feb 2007 15:57 GMT
The loop for multiple files is in another method, that calls this
WriteToFile with the filename string.
The pixels array is 2d array class variable,
short [][] pixels = new short [3][720*504];
> ..
>
[quoted text clipped - 7 lines]
>
> Andrew T.
Andrew Thompson - 23 Feb 2007 17:33 GMT
> The loop ..
What loop?
<http://www.physci.org/codes/javafaq.html#netiquette>
>..for multiple files is in another method, that calls this
> WriteToFile with the filename string.
>
> The pixels array is 2d array class variable,
> short [][] pixels = new short [3][720*504];
..good. Now getting back to what I actually
suggested.
> > Post an SSCCE?
<http://www.physci.org/codes/sscce.html>
The processing can be sped up by moving the
try/catch, as well as possibly some variable
declaration/initialisation, outside the loop.
But for the best answer, post an SSCCE
(as opposed to code snippets and descriptions).
Andrew T.
Knute Johnson - 24 Feb 2007 01:15 GMT
> Hello,
>
[quoted text clipped - 32 lines]
> e.getMessage() + " );
> }
You could buffer the output stream. Do you actually need to write
faster or just make it appear to the user that it went quickly?

Signature
Knute Johnson
email s/nospam/knute/