Trouver la couleur qui convient le mieux pour un texte
Bonjour
Presque tout est dans le titre comment, en fonction d'un fond en couleur trouver la meilleure couleur du texte (blanc ou noir) ?
Il doit certainement y avoir une réponse simple mais, moi et les couleurs ....
j'ai bien fait ce petit test
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| unit UnitColorFont;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
Data.Bind.EngExt, Fmx.Bind.DBEngExt, System.Rtti, System.Bindings.Outputs,
Fmx.Bind.Editors, Data.Bind.Components, FMX.Colors, FMX.Objects,
FMX.Controls.Presentation, FMX.StdCtrls, FMX.ScrollBox, FMX.Memo;
type
TForm64 = class(TForm)
RectangleTest: TRectangle;
TextTest: TText;
ComboColorBox1: TComboColorBox;
BindingsList1: TBindingsList;
LinkControlToPropertyFillColor: TLinkControlToProperty;
procedure ComboColorBox1Change(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form64: TForm64;
implementation
{$R *.fmx}
procedure TForm64.ComboColorBox1Change(Sender: TObject);
var C : TAlphaColorRec;
begin
C:= TAlphaColorRec(RectangleTest.Fill.Color);
if (C.R + C.G + C.B) > 384
then TextTest.TextSettings.FontColor:=TAlphaColorRec.Black
else TextTest.TextSettings.FontColor:=TAlphaColorRec.White;
end;
end. |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| object Form64: TForm64
Left = 0
Top = 0
Caption = 'Form64'
ClientHeight = 197
ClientWidth = 525
FormFactor.Width = 320
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
DesignerMasterStyle = 0
object RectangleTest: TRectangle
Fill.Color = claWhite
Position.X = 17.000000000000000000
Position.Y = 61.000000000000000000
Size.Width = 256.000000000000000000
Size.Height = 25.000000000000000000
Size.PlatformDefault = False
object TextTest: TText
Align = Client
Locked = True
Size.Width = 256.000000000000000000
Size.Height = 25.000000000000000000
Size.PlatformDefault = False
Text = 'ligne test '
end
end
object ComboColorBox1: TComboColorBox
Color = claWhite
Position.X = 288.000000000000000000
Position.Y = 62.000000000000000000
Size.Width = 60.000000000000000000
Size.Height = 22.000000000000000000
Size.PlatformDefault = False
TabOrder = 1
OnChange = ComboColorBox1Change
end
object BindingsList1: TBindingsList
Methods = <>
OutputConverters = <>
Left = 412
Top = 21
object LinkControlToPropertyFillColor: TLinkControlToProperty
Category = 'Liaisons rapides'
Control = ComboColorBox1
Track = True
Component = RectangleTest
ComponentProperty = 'Fill.Color'
end
end
end |
mais je trouve le résultat "limite"