Internal: How to Create an Image File of an Entire Widget
Anonym
Within IDL there are currently no routines that allow a user to create an image file of an entire widget, base included. There are a couple ways this can be done using external resources.
On a Windows platform, one can create a screen shot of an active widget by pressing Alt and Print Screen simultaneously. This copies an image to the clipboard, which can then be pasted into other applications.
On a Unix platform, one can call Xwd to create a screen shot and then convert it to an image file. This IDL code was submitted by Richard Fain of Indiana University Medical Center. It uses SPAWN to send a command to Xwd to create a screen shot of a widget, uses the IDL command READ_XWD to read the screen shot back into IDL, and save it as a GIF file.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Save_wid: IDL program to get create a standard GIF file of a selected window
Input: (optional) outfilehead -- file to be created not including .gif extension
Output: none
Side-effects: Creates .gif file in local directory as outfilehead.gif. If no filename
is supplied, the user will be prompted to enter one
Calling sequence: Save_wid, [outfilehead]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro save_wid, picfnme
if not arg_present(picfname) then begin ;; PROMPT FOR FILENAME IF NECESSARY
w_tmp = WIDGET_BASE(Title = 'Enter File Name Then Click On Window', /column)
temp = WIDGET_TEXT(w_tmp, xsize=50, ysize=1, /frame, /editable)
WIDGET_CONTROL, /REALIZE, w_tmp
temp_2 = WIDGET_EVENT(w_tmp)
WIDGET_CONTROL, temp_2.id, GET_VALUE = picfnme
picfnme = STRING(picfnme(0))
picfnme1 = strcompress(picfnme + '.xwd')
WIDGET_CONTROL, w_tmp, /CLEAR_EVENTS, /DESTROY
endif
command1 = 'xwd -out ' + picfnme1 ;; UNIX COMMAND FOR CAPTURING WINDOW
print, 'CLICK ON THE WINDOW TO SAVE'
spawn, command1 ;;INVOKE UNIX COMMAND
tmp_gif = read_xwd(picfnme1,R,G,B) ;;read into IDL
picfnme2 = strcompress(picfnme + '.png') ;;create png outfile name
print,picfnme2
WRITE_PNG, picfnme2,tmp_png,R,G,B ;;write to local directory as png file
command2 = 'rm ' + picfnme1;;remove
spawn, command2
end