O'Reilly logo

QuickTime for Java: A Developer's Notebook by Chris Adamson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Converting a Movie Image to a Java Image

It’s possible you’ll want to grab the current display of the movie and get it into a java.awt.Image. A convenient method call has been provided for just this task; unfortunately, it doesn’t work very well, so a Pict-based workaround is needed.

How do I do that?

QTJ provides QTImageProducer , an implementation of the AWT ImageProducer interface. ImageProducer dates back to Java 1.0, and was designed to handle latency and unreliability when loading images over the network—issues that are irrelevant in typical desktop cases.

The most straightforward way to get an image from a movie is to get a QTImageProducer from a MoviePlayer, the object typically used to create a lightweight, Swing-ready QTJComponent. The ConvertToImageBad application in Example 5-2 demonstrates this approach.

Note

Makes sense, doesn’t it? The MoviePlayer needs to generate AWT images for the lightweight QTJComponent, so that’s what you get an ImageProducer from.

Example 5-2. Using MoviePlayer’s QTImageProducer

package com.oreilly.qtjnotebook.ch05; import com.oreilly.qtjnotebook.ch01.QTSessionCheck; import java.awt.*; import java.awt.event.*; import javax.swing.*; import quicktime.*; import quicktime.app.view.*; import quicktime.io.*; import quicktime.qd.*; import quicktime.std.*; import quicktime.std.clocks.*; import quicktime.std.movies.*; public class ConvertToJavaImageBad extends Frame implements ActionListener { Movie movie; MoviePlayer player; MovieController controller; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required