QuickTime Java (QJT) is a terrific multimedia toolkit, but it's also terrifying to the uninitiated. Java developers who need to add audio, video, or interactive media creation and playback to their applications find that QTJ is powerful, but not easy to get into. In fact, when it comes to class-count, QuickTime Java is nearly as large as all of Java 1.1.Once you learn the entire scope of Apple's QuickTime software, you really appreciate the problem. At its simplest, QuickTime allows Mac and Windows users to play audio and video on their computers. But QuickTime is many things: a file format, an environment for media authoring, and a suite of applications that includes browser plug-ins for viewing media within a web page, a PictureViewer for working with still pictures, QuickTime Streaming Server for delivering streaming media files on the Internet in real time, and QuickTime Broadcaster for delivering live events on the Internet. Among others.As if that weren't daunting enough, the javadocs on QJT are wildly incomplete, and other books on the topic are long out of date and not well regarded, making progress with QTJ extremely difficult. So what can you do? Our new hands-on guide, QuickTime Java: A Developer's Notebook, not only catches up with this technology, but de-mystifies it.This practical "all lab, no lecture" book is an informal, code-intensive workbook that offers the first real look at this important software. Like other titles in our Developer's Notebook series, QuickTime Java: A Developer's Notebook is for impatient early adopters who want get up to speed on what they can use right now. It's deliberately light on theory, emphasizing example over explanation and practice over concept, so you can focus on learning by doing.QuickTime Java: A Developer's Notebook gives you just the functionality you need from QTJ. Even if you come to realize that 95% of the API is irrelevant to you, this book will help you master the 5% that really counts.
"synopsis" may belong to another edition of this title.
Chris Adamson is an Associate Online Editor for O'Reilly's Java websites, ONJava and java.net. He is also a software consultant, in the form of Subsequently and Furthermore, Inc., specializing in Java, Mac OS X, and media development. He wrote his first Java applet in 1996 on a 16 MHz black-and-white PowerBook 160 with the little-seen Sun MacJDK 1.0. In a previous career, he was a Writer / Associate Producer at CNN Headline News. He has an MA in Telecommunication from Michigan State University, and a BA in English and BS in Symbolic Systems from Stanford University.
CHAPTER 5 Working with QuickDraw
And now, on to the oldest, cruftiest, yet can’t-live-without-it-iest part of QTJ: QuickDraw. QuickDraw is a graphics API that can be traced all the way back to that first Mac Steve Jobs pulled out of a bag and showed the press more than 20 years ago. You know—back when Mac supported all of two colors: black and white.
Don’t worry; it’s gotten a lot better since then.
To be fair, a native Mac OS X application being written today from scratch probably would use the shiny new "Quartz 2D" API. And as a Java developer, the included Java 2D API is at least as capable as QuickDraw, with extension packages like Java Advanced Imaging (JAI) only making things better.
The real advantage to understanding QuickDraw is that it’s what’s used to work with captured images (see Chapter 6) and individual video samples (see Chapter 8). It is also a reasonably capable graphics API in its own right, supporting import from and export to many formats (most of which J2SE lacked until 1.4), affine transformations, compositing, and more.
Getting and Saving Picts
If you had a Mac before Mac OS X, you probably are very familiar with picts, because they were the native graphics file format on the old Mac OS. Taking screenshots would create pict files, as would saving your work in graphics applications. Developers used pict resources in their applications to provide graphics, splash screens, etc.
Actually, a number of tightly coupled concepts relate to picts. The native structure for working with a series of drawing commands is called a Picture actually. This struct, along with the functions that use it, are wrapped bythe QTJ class quicktime.qd.Pict. There’s also a file format for storing picts, which can contain either drawing commands or bit-mapped images—files in this format usually have a .pct or .pict extension. QTJ’s Pict class has methods to read and write these files, and because it’s easy to create Picts from Movies, Tracks, GraphicsImporters, SequenceGrabbers (capture devices), etc., it’s a very useful class.
How do I do that?
The PictTour.java application, shown in Example 5-1, exercises the basics of getting, saving, and loading Picts.
Example 5-1. Opening and saving Picts
package com.oreilly.qtjnotebook.ch05;
import quicktime.*;
import quicktime.app.view.*;
import quicktime.std.*;
import quicktime.std.image.*;
import quicktime.io.*;
import quicktime.qd.*;
import java.awt.*;
import java.io.*;
import com.oreilly.qtjnotebook.ch01.QTSessionCheck;
public class PictTour extends Object {
static final int[ ] imagetypes =$N202-1677793-2715858;
static int frameX = -1;
static int frameY = -1;
public static void main (String[ ] args) {
try {
QTSessionCheck.check( );
// import a graphic
QTSessionCheck.check( );
QTFile inFile = QTFile.standardGetFilePreview (imagetypes);
GraphicsImporter importer =
new GraphicsImporter (inFile);
showFrameForImporter (importer,
"Original Import");
// get a pict object and then save it
// then load again and show
Pict pict = importer.getAsPicture( );
String absPictPath = (new File ("pict.pict")).getAbsolutePath( );
File pictFile = new File (absPictPath);if (pictFile.exists( ))
pictFile.delete( );
try { Thread.sleep (1000); } catch (InterruptedException ie) { }
pict.writeToFile (pictFile);
QTFile pictQTFile = new QTFile (pictFile);
GraphicsImporter pictImporter =
new GraphicsImporter (pictQTFile);
showFrameForImporter (pictImporter,
"pict.pict");
// write to a pict file from importer
// then load and show it
String absGIPictPath = (new File ("gipict.pict")).getAbsolutePath( );
QTFile giPictQTFile = new QTFile (absGIPictPath);
if (giPictQTFile.exists( ))
giPictQTFile.delete( );
try { Thread.sleep (1000); } catch (InterruptedException ie) { }
importer.saveAsPicture (giPictQTFile,
IOConstants.smSystemScript);
GraphicsImporter giPictImporter =
new GraphicsImporter (giPictQTFile);
showFrameForImporter (giPictImporter,
"gipict.pict");
} catch (Exception e) {
e.printStackTrace( );
}
}
public static void showFrameForImporter (GraphicsImporter gi,
String frameTitle)
throws QTException {
QTComponent qtc = QTFactory.makeQTComponent (gi);
Component c = qtc.asComponent( );
Frame f = new Frame (frameTitle);
f.add (c);
f.pack( );
if (frameX = = -1) {
frameX = f.getLocation( ).x;
frameY = f.getLocation( ).y;
} else {
Point location = new Point (frameX += 20,
frameY += 20);
f.setLocation (location);
}
f.setVisible (true);
}
}
W A R N I N G
The two Thread.sleep( ) calls are here only as a workaround to aproblem I saw while developing this example—reading a file I’d just written proved crashy (maybe the file wasn’t fully closed?). Because it’s unlikely you’ll write a file and immediately reread it, this isn’t something you’ll want or need to do in your code.
"About this title" may belong to another edition of this title.
£ 2.82 shipping within U.S.A.
Destination, rates & speedsSeller: HPB-Red, Dallas, TX, U.S.A.
paperback. Condition: Good. Connecting readers with great books since 1972! Used textbooks may not include companion materials such as access codes, etc. May have some wear or writing/highlighting. We ship orders daily and Customer Service is our top priority! Seller Inventory # S_411238555
Quantity: 1 available
Seller: Books Puddle, New York, NY, U.S.A.
Condition: New. pp. xix + 233. Seller Inventory # 264172978
Quantity: 1 available
Seller: Majestic Books, Hounslow, United Kingdom
Condition: New. pp. xix + 233 Illus. Seller Inventory # 4723565
Quantity: 1 available
Seller: Biblios, Frankfurt am main, HESSE, Germany
Condition: New. pp. xix + 233. Seller Inventory # 184172984
Quantity: 1 available
Seller: Romtrade Corp., STERLING HEIGHTS, MI, U.S.A.
Condition: New. This is a Brand-new US Edition. This Item may be shipped from US or any other country as we have multiple locations worldwide. Seller Inventory # ABNR-183963
Quantity: 1 available
Seller: NEPO UG, Rüsselsheim am Main, Germany
Condition: Gut. Auflage: 1. 255 Seiten Exemplar aus einer wissenchaftlichen Bibliothek Sprache: Englisch Gewicht in Gramm: 356 23,2 x 17,4 x 2,0 cm, Taschenbuch. Seller Inventory # 379258
Quantity: 1 available