Alessandro71 Well-Known Member Licensed User Longtime User Apr 2, 2019 #1 Is there an easy way to draw a text label with complementary color? I have a text over a color changing background, so I need a way to make sure it's always readable.
Is there an easy way to draw a text label with complementary color? I have a text over a color changing background, so I need a way to make sure it's always readable.
Jeffrey Cameron Well-Known Member Licensed User Longtime User Apr 2, 2019 #2 Something like this? https://www.b4x.com/android/forum/t...rast-color-for-a-label-etc.26026/#post-264302 Upvote 0
Something like this? https://www.b4x.com/android/forum/t...rast-color-for-a-label-etc.26026/#post-264302
Alessandro71 Well-Known Member Licensed User Longtime User Apr 2, 2019 #3 This example is static: my background is dynamic and text may even be half over a color and half over another. Upvote 0
This example is static: my background is dynamic and text may even be half over a color and half over another.
Jeffrey Cameron Well-Known Member Licensed User Longtime User Apr 2, 2019 #4 So, Code: Copy Background.Color = NewColor Label1.TextColor = ContrastColor(NewColor) is not possible in your situation? Or are you saying the color is constantly changing? In that case your only real option is to set the Label1.Color to something not fully transparent thereby making it more readable regardless of background. If you're looking for some way to draw the label with XOR filter, then perhaps there's a way with JavaObject and Reflection, but I don't think there's a way with the standard label. Last edited: Apr 2, 2019 Upvote 0
So, Code: Copy Background.Color = NewColor Label1.TextColor = ContrastColor(NewColor) is not possible in your situation? Or are you saying the color is constantly changing? In that case your only real option is to set the Label1.Color to something not fully transparent thereby making it more readable regardless of background. If you're looking for some way to draw the label with XOR filter, then perhaps there's a way with JavaObject and Reflection, but I don't think there's a way with the standard label.
Erel B4X founder Staff member Licensed User Longtime User Apr 3, 2019 #5 Can you post a screenshot that demonstrates the effect you want to implement? Upvote 0
Alessandro71 Well-Known Member Licensed User Longtime User Apr 3, 2019 #6 here is a bad mockup the yellow background can change in color, and the level can wave just like water Attachments mockup.png 1.9 KB · Views: 342 Upvote 0
here is a bad mockup the yellow background can change in color, and the level can wave just like water
E emexes Expert Licensed User Longtime User Apr 4, 2019 #7 1/ how about semi-transparent label background (and perhaps the text too) eg Colors.ARGB(128, HowMuchRed, HowMuchGreen, HowMuchBlue) 1a/ or eg Code: Copy Dim BackgroundColor As Int = Colors.Whatever 'defaults to opaque (solid) (alpha = 255) Dim TextColor As Int = Colors.Whatever 'ditto BackgroundColor = Bit.Or(Bit.And(BackGroundColor, 0xFFFFFF), 0x40000000) 'change alpha to 64 (0x40) = mostly transparent TextColor = Bit.Or(Bit.And(TextColor, 0xFFFFFF), 0xC0000000) 'change alpha to 192 (0xC0) = mostly opaque (solid) 2/ or perhaps a shadow effect, eg, if the label text is white, then put an identical label underneath, but offset a few pixels down and right (or whatever direction you like) and with color black or grey 2b/ or you could likewise do a border, using eight labels underneath (offset in combinations of +/- vertically and +/- horizontally) but that's getting a bit tedious Upvote 0
1/ how about semi-transparent label background (and perhaps the text too) eg Colors.ARGB(128, HowMuchRed, HowMuchGreen, HowMuchBlue) 1a/ or eg Code: Copy Dim BackgroundColor As Int = Colors.Whatever 'defaults to opaque (solid) (alpha = 255) Dim TextColor As Int = Colors.Whatever 'ditto BackgroundColor = Bit.Or(Bit.And(BackGroundColor, 0xFFFFFF), 0x40000000) 'change alpha to 64 (0x40) = mostly transparent TextColor = Bit.Or(Bit.And(TextColor, 0xFFFFFF), 0xC0000000) 'change alpha to 192 (0xC0) = mostly opaque (solid) 2/ or perhaps a shadow effect, eg, if the label text is white, then put an identical label underneath, but offset a few pixels down and right (or whatever direction you like) and with color black or grey 2b/ or you could likewise do a border, using eight labels underneath (offset in combinations of +/- vertically and +/- horizontally) but that's getting a bit tedious
udg Expert Licensed User Longtime User Apr 4, 2019 #8 What abvout HSB/HSV color model? You could use the brightness part to catch whether the background turned darker or lighter and operate accordingly on the foreground text. Upvote 0
What abvout HSB/HSV color model? You could use the brightness part to catch whether the background turned darker or lighter and operate accordingly on the foreground text.
E emexes Expert Licensed User Longtime User Apr 4, 2019 #9 Just occurred to me that if you're adding the text to an image using Canvas.DrawText then it's pretty easy... instead of Code: Copy DrawText(S, X, Y, Black) you'd have Code: Copy for XOffset = -1 to 1 for YOffset = -1 to 1 if XOffset <> 0 or YOffset <> 0 then DrawText(S, X+XOffset, Y+YOffset, LightGray) 'draw gray border end if next next DrawText(S, X, Y, Black) 'draw text inside border and again you could experiment with making the border color semi-transparent with Colors.ARGB(A,R,G,B) where A is less than 255 Upvote 0
Just occurred to me that if you're adding the text to an image using Canvas.DrawText then it's pretty easy... instead of Code: Copy DrawText(S, X, Y, Black) you'd have Code: Copy for XOffset = -1 to 1 for YOffset = -1 to 1 if XOffset <> 0 or YOffset <> 0 then DrawText(S, X+XOffset, Y+YOffset, LightGray) 'draw gray border end if next next DrawText(S, X, Y, Black) 'draw text inside border and again you could experiment with making the border color semi-transparent with Colors.ARGB(A,R,G,B) where A is less than 255
Erel B4X founder Staff member Licensed User Longtime User Apr 4, 2019 #10 Check the attached example. Attachments 1.zip 1.zip 9.2 KB · Views: 315 Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Apr 4, 2019 #10 Check the attached example. Upvote 0
Alessandro71 Well-Known Member Licensed User Longtime User Apr 4, 2019 #11 effective, as always Upvote 0