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( ...

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.