Here are some examples of working with TIEBitmap.Scanline:
// Convert image to gray-scale (PixelFormat must be ie24RGB)
// Same as TImageEnProc.ConvertToGray
var
x, y: Integer;
pPix: PRGB;
Gray: Byte;
begin
for y := 0 to ImageEnView1.IEBitmap.Height - 1 do
begin
pPix := ImageEnView1.IEBitmap.ScanLine[ y ];
for x := 0 to ImageEnView1.SelectionMask.Width - 1 do
begin
Gray := (pPix^.R * IEGlobalSettings().RedToGrayCoef + pPix^.G * IEGlobalSettings().GreenToGrayCoef + pPix^.B * IEGlobalSettings().BlueToGrayCoef) div 100;
pPix^.R := Gray;
pPix^.G := Gray;
pPix^.B := Gray;
inc( pPix );
end;
end;
ImageEnView1.Update();
end;
// Set all pixels within selection as red
// Same as ImageEnView1.SetSelectedPixelsColor
var
x, y: Integer;
pSel: pbyte;
pPix: PRGB;
begin
if ImageEnView1.SelectionMask.IsEmpty then
raise Exception.create( 'Nothing selected' );
if ImageEnView1.IEBitmap.PixelFormat <> ie24RGB then
raise Exception.create( 'Not 24bit' );
// Process selected area
for y := 0 to ImageEnView1.SelectionMask.Height - 1 do
begin
pSel := ImageEnView1.SelectionMask.ScanLine[ y ];
pPix := ImageEnView1.IEBitmap.ScanLine[ y ];
case ImageEnView1.SelectionMask.BitsPerPixel of
1:
for x := 0 to ImageEnView1.SelectionMask.Width - 1 do
begin
// 1 Bit mask (values are 0 or 1)
if (pbytearray(pSel)^[x shr 3] and iebitmask1[x and $7]) <> 0 then
begin
pPix^.R := 255;
pPix^.G := 0;
pPix^.B := 0;
end;
inc( pPix );
end;
8:
for x := 0 to ImageEnView1.SelectionMask.Width - 1 do
begin
// 8 Bit mask (values are 0 to 255)
if pSel^ <> 0 then
begin
pPix^.R := 255;
pPix^.G := 0;
pPix^.B := 0;
end;
inc( pSel );
inc( pPix );
end;
end;
end;
ImageEnView1.Update();
end;
Nigel
Xequte Software
www.xequte.com
nigel@xequte.com