Mirror

Convert color value into gray-scaled color value (Views: 100)


Problem/Question/Abstract:

How can I convert the color value into gray-scaled value?

Answer:

If you want to convert a colored image into same gray scaled, then you must convert the color of the each pixel by the next schema:

function RgbToGray(Source: TColor): TColor;
var
  Target: Byte;
begin
  Target := Round((0.30 * GetRValue(Source)) +
    (0.59 * GetGValue(Source)) +
    (0.11 * GetBValue(Source)));
  Result := RGB(Target, Target, Target);
end;

<< Back to main page