
Handling Dropped Picts on Mac OS X #68
Chapter 9, Drag-and-Drop
|
349
HACK
Next is the QTJ stuff. It’s OK if you don’t totally understand it—QTJ code
is pretty twisted. That’s why there’s a whole book on it. First, you open a
QTSession
, which initializes QuickTime and allocates resources. You have to
do this before any QTJ call. It can throw a
QTException
, as can most other
QTJ calls, so the whole thing is wrapped in a
try
-
catch
block.
Next, you create a
Pict
object from the byte array and pass that to
DataRef
,
which is a sort of generic media reference. In this case, you pass in flags to tell
the
DataRef exactly what it’s pointing to. The second and third arguments
indicate that we’re using the old-style Mac OS file type and that its value is
PICT. You might be wondering why being a Pict object isn’t self-descriptive
enough. It’s because many QTJ objects are just pointers to blocks of memory
and the functions that work with them. The
DataRef signature used here
takes a
QTHandleRef as an argument. QTHandleRef is subclassed by Pict, but it
is little more than a pointer; the only level on which the
DataRef understands
the
Pict, in fact, is as a block of memory. My point here: QTJ code is weird
and often C-like.
Create a
GraphicsImporter for the Pict format, and point it to the DataRef.
You have now read the Pict “file” from memory. Now, you can get the size
of the imported image and create a
QTImageProducer, with ...