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

Drawing with Graphics Primitives

In AWT, a Graphics object represents a drawing surface—either on-screen or off-screen—and supplies various methods for drawing on it. QuickTime has a GWorld object that’s so similar, the QT developers renamed it QDGraphics just to make Java developers feel at home. As with the AWT class, painting is driven by a callback mentality.

How do I do that?

Example 5-4 shows the GWorldToPict example, which creates a QDGraphics object and performs some simple drawing operations.

Example 5-4. Drawing on a QDGraphics object

package com.oreilly.qtjnotebook.ch05; import quicktime.*; import quicktime.std.*; import quicktime.std.image.*; import quicktime.qd.*; import com.oreilly.qtjnotebook.ch01.QTSessionCheck; public class GWorldToPict extends Object implements QDDrawer { public static void main (String[ ] args) { new GWorldToPict( ); } public GWorldToPict( ) { try { QTSessionCheck.check( ); QDRect bounds = new QDRect (0, 0, 200, 250); ImageDescription imgDesc = new ImageDescription(QDConstants.k32RGBAPixelFormat); imgDesc.setHeight (bounds.getHeight( )); imgDesc.setWidth (bounds.getWidth( )); QDGraphics gw = new QDGraphics (imgDesc, 0); System.out.println ("GWorld created: " + gw); OpenCPicParams params = new OpenCPicParams(bounds); Pict pict = Pict.open (gw, params); gw.beginDraw (this); pict.close( ); try { pict.writeToFile (new java.io.File ("gworld.pict")); } catch (java.io.IOException ioe) { ioe.printStackTrace( ); } } catch (QTException qte) { qte.printStackTrace( ...

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