home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / createpictfile / src / createpictfile.java
Encoding:
Java Source  |  2000-06-23  |  2.7 KB  |  99 lines

  1. /*
  2.  * QuickTime for Java SDK Sample Code
  3.  
  4.    Usage subject to restrictions in SDK License Agreement
  5.  * Copyright: © 1996-1999 Apple Computer, Inc.
  6.  
  7.  */
  8. import java.io.File;
  9. import java.awt.event.*;
  10.  
  11. import quicktime.*;
  12. import quicktime.app.*;
  13. import quicktime.qd.*;
  14. import java.awt.*;
  15. import quicktime.app.display.*;
  16. import quicktime.std.*;
  17. import quicktime.app.image.*;
  18. import quicktime.io.QTFile;
  19. import quicktime.util.*;
  20. import quicktime.std.StdQTConstants;
  21.  
  22.  
  23. public class CreatePictFile extends Frame implements StdQTConstants {
  24.  
  25.     Pict myPict;
  26.     CreatePictFile cd;
  27.     
  28.     public static void main(String args[]) {        
  29.         try {
  30.             QTSession.open();
  31.             CreatePictFile cd = new CreatePictFile();
  32.             cd.show();
  33.             cd.toFront();
  34.         } catch (Exception e) {
  35.             e.printStackTrace();
  36.             QTSession.close();
  37.         }
  38.     }
  39.     
  40.     CreatePictFile () throws Exception {
  41.         super ("QT in Java");
  42.         addWindowListener(new WindowAdapter () {
  43.             public void windowClosed(WindowEvent inEvent) {
  44.                 System.exit(0);
  45.             }
  46.                 
  47.             public void windowClosing(WindowEvent inEvent) {
  48.                 QTSession.close();
  49.                 dispose();
  50.             }
  51.         });
  52.         QTCanvas myQTCanvas = new QTCanvas(QTCanvas.kAspectResize, 0, 0);
  53.         add("Center", myQTCanvas);
  54.                     
  55.         addNotify();
  56.         Insets insets = getInsets();
  57.         setBounds (0, 0, (insets.left + insets.right + 500), (insets.top + insets.bottom + 300));
  58.  
  59.         Button b = new Button ("Click here to create a PICT File of window's contents");
  60.         b.addActionListener (new ActionListener () {
  61.             public void actionPerformed (ActionEvent event) {
  62.                 try {
  63.                     myPict.writeToFile(new File("results.pict"));                            
  64.                 } catch (Exception ex) { 
  65.                     ex.printStackTrace();
  66.                 }                        
  67.             }
  68.         });
  69.         
  70.         add("North", b);
  71.         
  72.         int[] fileTypes = { kQTFileTypeGIF, kQTFileTypeJPEG, kQTFileTypePicture };
  73.         QTFile qtf = QTFile.standardGetFilePreview (fileTypes);
  74.  
  75.         GraphicsImporterDrawer myImageFile = new GraphicsImporterDrawer (new QTFile(qtf));
  76.  
  77.         QDGraphics recordingGraphics = new QDGraphics (myImageFile.getDisplayBounds());
  78.         myImageFile.setGWorld (recordingGraphics);
  79.         
  80.             //Note that the last 2 Parameters to OpenCPicParams represent the resolution in DPI - the default is 72
  81.         OpenCPicParams param = new OpenCPicParams(myImageFile.getDisplayBounds());
  82.             
  83.             // whenever you draw to a QDGraphics from which
  84.             // you are creating a PICT you MUST set
  85.             // the GWorld first and retain it as the current 
  86.             // GWorld whilst open, draw then close
  87.         myPict = Pict.open (recordingGraphics, param);
  88.         
  89.             SetGWorld sg = new SetGWorld(recordingGraphics);
  90.             myImageFile.redraw(null);
  91.             sg.reset();
  92.         
  93.         myPict.close();
  94.                     
  95.         ImagePresenter ip = ImagePresenter.fromPict (myPict);
  96.         myQTCanvas.setClient (ip, true);
  97.     }
  98. }
  99.