pro SCREEN_GRAB, file, format = format, jpg = jpg, gif = gif, $ png = png, tiff = tiff, bmp = bmp, ps = ps, back = back ;+ ; NAME: ; SCREEN_GRAB ; ; PURPOSE: ; Write current window contents to file ; ; CATEGORY: ; Procedure - Utility - Send output to file ; ; INPUTS: ; None ; ; OPTIONAL INPUTS: ; file file name (defaults to pickfile) ; ; KEYED INPUTS: ; format format for image file ; ; jpg specfies jpg format (default) ; gif specfies gif format (may not be supported by some IDL licenses ; due to patent reasons) ; png specifies png format ; tiff specfies tiff format ; bmp specfies bmp format ; ps specifies ps format (not recommended!) ; ; back change "background" pixels to white and "foreground" pixels ; to black. In so doing, it is assumed that background color ; in the original image is indexed as "255" and foreground color ; as "0", pixels having these colors are pickes and thir colors ; are inverted, while other colors are left untouched, even if ; any color "combination" will change as well as a side effect. ; While this should work if one runs "COLOURS" first, these ; defaults may not reflect your color table of choice, therefore ; use BACK with care! ; ; COMMON BLOCKS: ; COLORS colour look-up table ; ; EXAMPLES: ; screen_grab,$ ; [file, format=format, gif=gif, bmp=bmp, jpg=jpg,$ ; tiff=tiff, png=png, ps=ps, back=back] ; ; SIDE EFFECTS: ; Writes file to disk ; ; MODIFICATION HISTORY: ; 01 Apr 2001 Adapted from Seb Oliver's SCREEN_GRAB by Mattia Vaccari ; by adding support for PS and PNG outout ; ; 11 Jun 2001 JPEG support added and BACK keyword removed (Mattia Vaccari) ; 06 Aug 2004 JPG & JPEG equivalent keywords now both supported (Mattia Vaccari) ; 21 Oct 2004 JPEG keyword dropped (Use JPG instead!) and BACK keyword reintroduced (Mattia Vaccari) ;- on_error,2 common colors, r_orig,g_orig,b_orig,r_cur,g_cur,b_cur if keyword_set(tiff) then format='tif' if keyword_set(gif) then format='gif' if keyword_set(jpg) then format='jpg' if keyword_set(bmp) then format='bmp' if keyword_set(png) then format='png' if keyword_set(ps) then format='ps' if not keyword_set(format) then begin print,'No file type specified! Using jpg' format='jpg' endif if n_params() lt 1 then file=pickfile(filter='*.'+format) if format ne 'jpg' then im0=tvrd() else im0=tvrd(true=1) if keyword_set(back) then begin towhite=where(im0 eq 0B) ; Choose pixels with "background" color toblack=where(im0 eq 255B) ; Choose pixels with "foreground" color if (towhite(0) ne -1) then im0(towhite)=255B if (toblack(0) ne -1) then im0(toblack)=0B endif case strupcase(strmid(format,0,3)) of 'JPG' : write_jpeg,file,im0,true=1 'GIF' : write_gif,file,im0,r_cur,g_cur,b_cur 'PNG' : write_png,file,im0,r_cur,g_cur,b_cur 'TIF' : tiff_write,file,im0,red=r_cur,green=g_cur,blue=b_cur 'BMP' : write_bmp,file,im0,r_cur,g_cur,b_cur 'PS' : begin print,'PS not recommended!' set_plot,'ps' device,filename=file tvscl,im0 device,/close set_plot,'x' end else : message,'Format: '+format+' not recognised' endcase end