IDL 8.2: 32-bit (RGBA) bitmap images are now supported
In IDL 8.2, 32-bit (RGBA) bitmap (.bmp) files can now be used to create image labels for buttons. This allows you to easily use RGBA files created using IDL 8.2 or graphic programs such as PhotoShop image labels.
Opening and displaying an RGBA bitmap file
Each pixel in an RGBA image has 4 byte values associated with it. The RGB (Red, Green and Blue) values describe the color of the pixel. The A (alpha) value describes the transparency of the pixel. A pixel with an alpha value of 255 has zero transparency (completely opaque). An example RGBA bitmap file is attached below (right click on the image, select "Save image as" and save it as 'btmap_alpha_ex.bmp" in your IDL path ):
The first thing that you might notice if you use READ_BMP to read the image, and display it, is that the Red and Blue colors have been switched. For example:
file = file_which('btmap_alpha_ex.bmp')
t_img = READ_BMP(file)
i = image(t_img, TITLE='Color wrong', LAYOUT=[2,1,1])
This occurs because .bmp files store images in the order of BGR. To get around this issue, you can use the RGB keyword with READ_BMP.
file = file_which('btmap_alpha_ex.bmp')
t_img2 = READ_BMP(file, /RGB)
i2 = image(t_img2, TITLE='Color correct /RGB',/CURRENT, LAYOUT=[2,1,2])

Using an RGBA bitmap file for button label
To specify an image file as a button label, you can use the VALUE and BITMAP keyword. This can seen below:
file = file_which('btmap_alpha_ex.bmp')
base=WIDGET_BASE() ;create the widget base
button=WIDGET_BUTTON(base,VALUE=file,/BITMAP) ;create the widget button
widget_control,base,/REALIZE
Using a 4-D array for button label
To use a 4-D array to generate a button, you must provide the WIDGET_BUTTON with a [n,m,4] array using the VALUE keyword. The example shown below should produce the same image on the button as the image in the previous section.
file = file_which('btmap_alpha_ex.bmp')
t_img2 = READ_BMP(file, /RGB)
button_img = transpose(t_img2, [1,2,0])
base2=WIDGET_BASE()
button2=WIDGET_BUTTON(base2,VALUE=button_img)
widget_control,base2,/REALIZE
Writing an RGBA file
In IDL 8.2, the WRITE_BMP function now supports 32-bit bitmap files. Therefore you can now use this function to write 4-D arrays to bitmap files. An example is shown below (notice the interleaving of the array being written the file is [4,n,m]).
temp_img=BYTARR(4,100,100)
temp_img[1,25:50,25:50]=255
temp_img[0,0:25,0:25]=255
temp_img[2,50:75,50:75]=255
temp_img[3,*,*]=100
WRITE_BMP,"ex_transparent_file.bmp",temp_img
Reviewed by DS 9/17/2014