X
3788

IDL 8.2: Change in behavior when using 3-D arrays for button icons on Windows

IDL widget buttons can be labeled using images. To do this, you can provide the WIDGET_BUTTON function with a bitmap file, a 4-D array, or a 3-D array.  In IDL 8.2, the behavior of the WIDGET_BUTTON function has changed when a 3-D array is used to generate the label on Windows systems. For example, in IDL 8.1, you can enter in the following code into IDL and it will create a button that has three boxes (colored red, green and blue) on  a black background:

test_img = BYTARR(100,100,3)
test_img[25:50,25:50,1]=255
test_img[0:25,0:25,0]=255
test_img[50:75,50:75,2]=255

base=WIDGET_BASE() ;create the widget base
button=WIDGET_BUTTON(base,VALUE=test_img)  ;create the widget button
widget_control,base,/REALIZE

However, If you are using IDL 8.2 on Windows, you will notice that the box in the bottom left corner is colored grey (it should be colored red).

IDL 8.1 (correct color)                   

 Caption: Left picture: button as it would appear in IDL8.1 (the color is correct).
Right picture: button as it appear in IDL 8.2 (bottom corner grayed out).

There are three methods you could use to get the color to display correctly:

1) You can set the MASK keyword with the WIDGET_BUTTON to zero. By default the Mask keyword of the WIDGET_BUTTON is set to 1. On Windows, this makes the pixel value in the bottom left-hand corner of the image transparent. If you set MASK=0, it removes the gray from the image:

base=WIDGET_BASE() ;create the widget base
button=WIDGET_BUTTON(base,VALUE=test_img, MASK=0)  ;create the widget button
widget_control,base,/REALIZE

2) Change the value in the lower left pixel to a color that is not used anywhere else in the image. For example, you could add the "test_img[ 0, 0, 0 ] = 254" before creating the button in the example code.

3) You can convert the 3-D array (RGB) to a 4-D array (RGBA) with the alpha values all set to 255. For example:


test_img = BYTARR(100,100,3)
test_img[25:50,25:50,1]=255
test_img[0:25,0:25,0]=255
test_img[50:75,50:75,2]=255


;get the version information

vers = !version.RELEASE
vers = float(vers)


if (vers gt 8.1) then begin ;check if version is IDL 8.2


     temp_img=BYTARR(100,100,4)
     temp_img[0,0,0]=test_img
     temp_img[*,*,3]=255
     test_img=temp_img

endif



base=WIDGET_BASE() ;create the widget base

button=WIDGET_BUTTON(base,VALUE=test_img)  ;create the widget button
widget_control,base,/REALIZE