try {
// stop movie to take picture
boolean wasPlaying = false;
if (movie.getRate() > 0) {
movie.stop();
wasPlaying = true;
}
// take a pict
Pict pict = movie.getPict (movie.getTime());
// add 512-byte header that pict would have as file
byte[] newPictBytes =
new byte [pict.getSize() + 512];
pict.copyToArray (0,
newPictBytes,
512,
newPictBytes.length - 512);
pict = new Pict (newPictBytes);
/*
// debug to disk
try {
FileOutputStream out =
new FileOutputStream (new File ("newpict.pict"));
out.write (newPictBytes, 0, newPictBytes.length);
out.flush();
out.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
*/
// export it
DataRef ref = new DataRef (pict,
StdQTConstants.kDataRefQTFileTypeTag,
"PICT");
gi.setDataReference (ref);
QDRect rect = gi.getSourceRect ();
Dimension dim = new Dimension (rect.getWidth(),
rect.getHeight());
QTImageProducer ip = new QTImageProducer (gid, dim);
/*
// sanity check by getting a qtcomponent
QTComponent giqtc = QTFactory.makeQTComponent (gi);
Component gic = giqtc.asComponent();
Frame f = new Frame ("GraphicsImporter");
f.setLayout (new BorderLayout());
f.add (gic);
f.pack();
f.setVisible(true);
*/
// convert from MoviePlayer to java.awt.Image
Image image = Toolkit.getDefaultToolkit().createImage (ip);
// make a swing icon out of it and show it in a frame
ImageIcon icon = new ImageIcon (image);
JLabel label = new JLabel (icon);
JFrame frame = new JFrame ("Java image");
frame.getContentPane().add(label);
frame.pack();
frame.setLocation (nextFrameX += 10,
nextFrameY += 10);
frame.setVisible(true);
// restart movie
if (wasPlaying)
movie.start();
} catch (QTException qte) {
qte.printStackTrace();
}