Главная страница | назад

Article #17780: Color problems in 256 color mode.

 Question and Answer Database

FAQ2780D.txt   Color problems in 256 color mode.
Category   :VCL
Platform    :All
Product    :All 32 bit  

When I am drawing graphics with my application in 256 color
mode (or less), some pen and text colors do not match my 
brush colors.

Unless you are using a palette, Windows will attempt to 
convert pen and text colors to the nearest pure color 
available. You can determine the nearest pure color, a given 
color will map to, by calling the Windows API function 
GetNearestColor(). If you wish to use dithered colors for a 
pen, you can also set the pen style to the psInsideFrame 
style. When using this style, the pen draws lines within the 
frame of closed shapes that specify a bounding rectangle 
instead of centering the line over the shape. For the 
psInsideFrame style to have an effect, the pen width must be 
larger than 1 pixel.


procedure TForm1.Button1Click(Sender: TObject);
var NearestColor : TColorRef;
  Form1.Canvas.Brush.Color := RGB(143, 53, 22);
  Form1.Canvas.Pen.Color := RGB(143, 53, 22);
  Form1.Canvas.Pen.Width := 10;
  Form1.Canvas.Ellipse(10, 10, 100, 100);
  Form1.Canvas.Pen.Style := psInsideFrame;
  Form1.Canvas.Ellipse(10, 110, 100, 200);
     'The nearest displayable color to RGB(143, 53, 22) is:');
  NearestColor :=
                    RGB(143, 53, 22));
  Memo1.Lines.Add('Red := ' +
  Memo1.Lines.Add('Red := ' +
  Memo1.Lines.Add('Blue := ' +

7/16/98 4:31:28 PM

Last Modified: 01-SEP-99