Coyote's Guide to IDL Programming

Sending a Graphics Screen Dump to a PostScript File

QUESTION: Can I just dump the contents of an IDL graphics window to a PostScript file?

ANSWER: You can, but are you sure you want to? Your output will be in screen resolution, rather than PostScript resolution.

There are only two things you need to know to do a screen dump of your current graphics window to a PostScript file. First, you need to know how to get a copy of your screen. You do that by taking a "snap-shot" of your current graphics window with the TVRD command, like this:

   screenDump = TVRD(True=1)

Note that you can use the program cgSnapshot from the Coyote Library to take a screen dump in a device-independent fashion.

   screenDump = cgSnapshot()

One advantage of cgSnapshot is that you can also immediately send the contents of screen to a JPEG, TIFF, PNG, etc. file, just by setting keywords. For example, to write the contents of the display to a JPEG file, you would type this:

   screenDump = cgSnapshot(/JPEG)

Second, you need to know how to create a PostScript output "window" with the same aspect ratio as the graphics display window. I normally use the program PSWindow for that purpose.

I have written short program named ScreenDump that you can use as an example of how easy it is to send a screen dump of the current graphics window to a PostScript file. Here is the code for the program.

SCREENDUMP.PRO

   PRO SCREENDUMP, filename, Encapsulated=encapsulated

      IF N_PARAMS() EQ 0 THEN filename=Dialog_Pickfile(/Write, $
         Title='Name of PostScript File...', File='screendump.ps')

      ; Get the screen dump of the current graphics window.
      screenDump = cgSnapShot()

      ; Make a PostScript window with the same aspect
      ; ratio as the current display window. Use color
      ; PostScript if the COLOR keyword is set.
      aspect = PSWINDOW()

      ; Open a PostScript file and dump it.
      thisDevice = !D.NAME
      SET_PLOT, 'PS', /Copy
      DEVICE, FILENAME=filename, XSIZE=aspect.xsize, YSIZE=aspect.ysize, $
         XOFFSET=aspect.xoffset, YOFFSET=aspect.yoffset, COLOR=1, $
         ENCAPSULATED=Keyword_Set(encapsulated), Inches=aspect.inches, $
         DECOMPOSED=1

      ; Display the screen dump. Fill up the window.
      cgImage, screenDump
      DEVICE, /CLOSE_FILE
      SET_PLOT, thisDevice

   END

Google
 
Web Coyote's Guide to IDL Programming