Xbasic

CHANGE_COLOR Function

Syntax

V CHANGE_COLOR(N XPos,N YPos,N Width,N Height,C search_colors,C replace_colors[,C nomatch_color])

Arguments

XPos

The horizontal coordinate of the upper left corner of the rectangular area to be modified.

YPos

The vertical coordinate of the upper left corner of the rectangular area to be modified.

Width

The width of the rectangular area to be modified.

Height

The height of the rectangular area to be modified.

search_colors

The colors to search for.

replace_colors

The colors to substitute.

nomatch_color

Optional.

Description

The CHANGE_COLOR() function changes the colors of pixels in a specified area.

Example

The blue halo around the red letters below is because the font engine smooths (anti-aliases) between the original blue fill color and the white background, resulting in a variety of other blue colors that are not being replaced.

images/GR_change_color.gif
ui_bitmap_create("test", 4, 1)
ui_bitmap_draw("test",<<%code%
set_font("Verdana,20,biu", "blue", "white")
inner_Rect(0, 0, 4, 1)
text("Sample", bitmap_width("test")/2, bitmap_height("test")/2, "center")
change_color(0,0,2,1,"blue","red")
%code%)
ui_dlg_box("","{image=test}")

The next example changes three search colors to three replace colors.

images/GR_change_color2.gif
ui_bitmap_draw("test",<<%code%
inner_Rect(0, 0, 4, 2)
set_pen("white")
set_brush("cyan")
fill_rect(0, 0, 1.33, 2)
set_brush("Dark Cyan")
fill_rect(1.34, 0, 1.33, 2)
set_brush("Blue")
fill_rect(2.68, 0, 1.33, 2)
fromcolor = <<%str%
Cyan
Dark Cyan
Blue
%str%
tocolor = <<%str%
Gray-25
Gray-40
Black
%str%
change_color(0, 1, 4, 1, fromcolor, tocolor)
%code%)
ui_dlg_box("","{image=test}")

Limitations

Used only in the Code sections of UI_BITMAP_DRAW(), UI_SCREEN_DRAW(), and UI_PRINTER_DRAW().

See Also