Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2007

Tip: Looking for answers? Try searching our database.

Looking for a way to speed up png file writing

Thread view: 
kmsterrett - 23 Feb 2007 15:14 GMT
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/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.