| |
| Color problems in 256 color mode. |
 |
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 pixel.
Example:
procedure TForm .Button Click(Sender: TObject);
var NearestColor : TColorRef;
begin
Form .Canvas.Brush.Color := RGB( 43, 53, 22);
Form .Canvas.Pen.Color := RGB( 43, 53, 22);
Form .Canvas.Pen.Width := 0;
Form .Canvas.Ellipse( 0, 0, 00, 00);
Form .Canvas.Pen.Style := psInsideFrame;
Form .Canvas.Ellipse( 0, 0, 00, 200);
Memo .Lines.Add(
'The nearest displayable color to RGB( 43, 53, 22) is:');
NearestColor :=
GetNearestColor(Form .Canvas.Handle,
RGB( 43, 53, 22));
Memo .Lines.Add('Red := ' +
IntToStr(GetRValue(NearestColor)));
Memo .Lines.Add('Red := ' +
IntToStr(GetGValue(NearestColor)));
Memo .Lines.Add('Blue := ' +
IntToStr(GetBValue(NearestColor)));
end;
|
|
| Hits/month |
2,500,000+ |
Downloads (Since May 2000) |
7,393,709 |
| Total Files |
6,023 |
| Forum msgs |
7,670 |
| Articles/FAQs |
70+/900+ |
Top Selling Software at Amazon
|