FUNCTION qImage_Pick, state, image
    @compile_opt.pro        ; On error, return to caller

; Pick up file filter from widget

widget_control, state.wid_folder, get_value=folder
widget_control, state.wid_filter, get_value=filter
filter = filepath(root=unhide_env(folder[0]),filter[0])

; Check for the presence of wildcards

wildcard = strpos(filter, '*') NE -1 OR     $
           strpos(filter, '?') NE -1 OR     $
           strpos(filter, '%') NE -1

; Use pickfile dialog if a wildcard was found; otherwise
; just try to read the file

CASE wildcard OF
0: file = filter
1: BEGIN    ; Select single file
    SetFileSpec, filter

    file = dialog_pickfile( $
        path   = GetFileSpec(upto='directory'),             $
        filter = GetFileSpec(from='name',upto='type'),  $
        group  = state.wid_pick, title='Select image file')

    file = file[0]
END
ENDCASE

status = file NE ''

IF status THEN BEGIN

    widget_control, state.wid_ftsext, get_value=exten_no

    status = img_read(file, tmp, /pseudo, img_info=info, exten_no=exten_no)

    CASE status OF
    0: tmp = dialog_message('Error reading image file '+file)
    1: BEGIN
        image = tmp

        tmp = IsType(image, name=name)
        tmp = size(image, /dim)

        info = [file,' ',strjoin( strcompress(tmp, /rem), ' x ')+' '+name+' array', ' ', info[0]]

        widget_control, state.wid_info, set_uvalue=info, /no_copy

        ; Centroid calculations require float array

        IF IsType(image, /generic_int) THEN image = float(image)

    END
    ENDCASE

ENDIF

RETURN, status  &  END