Introduction - If you have any usage issues, please Google them yourself
procedure GrayScale(const Image:TImage)
var
BytesPerScan: Integer
iWidth, iHeight: Integer
pScanLine: pByteArray
R,G,B: Byte
begin
try
BytesPerScan := Abs(Integer(Image.Picture.Bitmap.ScanLine[1])-
Integer(Image.Picture.Bitmap.ScanLine[0]))
except
raise exception.create(‘Error’)
end
for iHeight := 0 to Image.Picture.Bitmap.Height - 1 do
begin
pScanLine := Image.Picture.Bitmap.ScanLine[iHeight]
iWidth := 0
while(iWidth <= BytesPerScan - 1) do
begin
R := pScanLine^[iWidth + 2]
G := pScanLine^[iWidth + 1]
B := pScanLine^[iWidth + 0]
pScanLine^[iWidth + 2] := Byte(Round(0.299 * R + 0.587 * G + 0.114 * B))
pScanLine^[iWidth + 1] := Byte(Round(0.299 * R + 0.587 * G + 0.114 * B))
pScanLine^[iWidth + 0] := Byte(Round(0.299 * R + 0.587 * G + 0.114 * B))
iWidth := iWidth + 3
end
end
Image.Refresh
end