Get the color table

This particular trick is very useful when you want to export an image out of IDL, for instance to post on a web page, or send to a colleague. It does not apply when you want to create a postcript file, but rather anytime you want to create a GIF (no longer available after 5.41), BMP, NRIF, PICT, or SRF image.

Typically what you do is you display your data in an IDL window, you add some comments, arrows, symbols, you adjust the color table so that what you want to show really shows up, and then you want to store the result in an image.

Your first option is to grab your window with an external software (efficient but not elegant).

Your second option is to use the write_xxx routines of IDL. First, you need to get the displayed data in an array and this is simply done with:

	my_array = tvrd()

The routine reads the content of the current graphic window (you can aslo tell it to read a given portion of that window with appropriate parameters). Alternatively if you did not overplot anything, the only thing to do is to convert your data into bytes (with the byte function), because these formats will only store bytes.

Now the tricky thing is to get the color table correctly. Indeed, so far you only have the intensity (basically you have a black and white image). This is done with the tvlct function. As the name can imply for the sharp-eyed, this routine loads a color table, here described by three 256 elements vector, the red, green and blue vectors. But it can also be used to read the current values of these vectors with:


Now you have all you need, the intensity and the current color table so you should be able to create your image with, for instance:


and it should be identical to your screen.

1GIF is a proprietary format and in order to comply with that, IDL no longer gives the possibility to write GIF images.