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; ...
Get QuickTime for Java: A Developer's Notebook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.