tags:

views:

1986

answers:

2

I tried both of the following options:

<1>

BufferedImage Buffered_Image;
MemoryCacheImageOutputStream MemoryCache_OutputStream=new MemoryCacheImageOutputStream(new FileOutputStream("C:/Test.mov",false));

while (notFinished)  // Main recording loop.
{
   Buffered_Image=robot.createScreenCapture();         // Capture Screen image.
   try { ImageIO.write(Buffered_Image,"png",MemoryCache_OutputStream); }
   catch (Exception e) { e.printStackTrace(); }
}

<2>

BufferedImage Buffered_Image;
ImageWriter writer;
try
{
  ImageOutputStream ios=ImageIO.createImageOutputStream(new File("C:/Test.mov"));
  Iterator writers=ImageIO.getImageWritersByFormatName("png");
  while (writers.hasNext())
  {
    writer=(ImageWriter)writers.next();
    writer.setOutput(ios);
    Out(writer.toString()+"  canInsertImage : "+writer.canInsertImage(0));                 
    // Got this: com.sun.imageio.plugins.png.PNGImageWriter@19fcc69  canInsertImage : false
  }
}
catch (Exception e) { }

cntPics=0;
while (notFinished)  // Main recording loop.
{
   Buffered_Image=robot.createScreenCapture();         // Capture Screen image.
   writer.write(null,new IIOImage(Buffered_Image,null,null),null);
   if (writer.canInsertImage(-1)) writer.writeInsert(-1,new IIOImage(Buffered_Image,null,null),null); // Append image at highest index
   else Out("Writer can’t append image Id : "+cntPics);
   cntPics++;
}

Neither of them worked, what's the correct way to save multiple PNG images to a file?

Frank

Edit:

You are right, I found a java program called Krut that can record screen sessions, but it uses JPEGImageEncoder, the image quality isn't as good as I want, so I wonder if I can use ImageIO to encode the sequence.

If ImageIO can't do it, my next question would be is there a stand alone open source PNGImageEncoder that I can use to encode it? I know there are open source PNGImageEncoders, but they tend to be tangled in projects and hard to get all the supporting files out of it, any ideas? Thanks!

+1  A: 

It looks like you're trying to create a video (MOV) file by writing multiple PNG files in a row. This isn't going to work. You'll probably have to find a third-party library for encoding your images into a video file (which is itself may be a good SO question).

EDIT: I should also note that you may actually be able to get video by writing multiple JPG images in a row to get a form of MJPEG (Motion JPEG) but for other formats such as MOV you're going to need an actual encoder.

Marc Novakowski
A: 

What are you trying to do? Re-inventing MNG? Even if you can write multiple PNG images in the same file, it makes a compound file understood by no program (except those you might write).

If, as suggested by Marc, you want to make a movie, you might want to look at QuickTime for Java (QTJava). It is the solution used by Processing to make movies out of animations/frames. It has several quality/formats, from the worst (but small files) to the highest quality (high file sizes as result).

PhiLho
Oh, I never heard of it, can it record screen sessions and sound from a PC ? If you are watching a video with sound on PC, can it record that into a movie ? Or if you want to make an instructional video of how to use a PC program with mouse clicks and your voice from a microphone can it record it ?
Frank
Do you really need to code that (eg. to integrate in some software)? If not, you have already lot of tools. For example http://stackoverflow.com/questions/280362 or http://stackoverflow.com/questions/24555
PhiLho