Un barrido podría ser visto como ésto;
Código Delphi
[-]...
y := bmp.Height;
repeat Dec(y); x := bmp.Width;
repeat Dec(x); Color := bmp.Canvas.Pixels[X, Y];
if GetRValue(Color) > 10 then
bmp.Canvas.Pixels[X, Y] := RGB(GetRValue(Color) - 10, GetGValue(Color), GetBValue(Color));
until not LongBool(x);
until not LongBool(y);
...
ó con el uso de un
while o un
for (simplemente un bucle dentro de otro), sin embargo se puede hacer un barrido de toda la imagen directamente en memoria, lo que mejoraría conciderablemente la velocidad de acceso y el trabajo plano en un vector (a diferencia de en una matriz XY como la del anterior ejemplo).
Código Delphi
[-]uses jpeg;
procedure TForm1.Button1Click(Sender: TObject);
var
jpg: TJPEGImage;
bmp: TBitmap;
Count: Cardinal;
lpBuffer: PByte;
begin
jpg := TJPEGImage.Create;
jpg.LoadFromFile('c:\windows\web\wallpaper\autumn.jpg');
bmp := TBitmap.Create;
bmp.Assign(jpg);
bmp.PixelFormat := pf24bit;
Count := bmp.Width * bmp.Height;
lpBuffer := PByte(Cardinal(bmp.ScanLine[bmp.Height - 1]) + 2);
while LongBool(Count) do begin
if lpBuffer^ > 64 then Dec(lpBuffer^, 64); Inc(lpBuffer, 3);
Dec(Count);
end;
Image2.Picture.Assign(bmp);
Image1.Picture.Assign(jpg);
bmp.Destroy;
jpg.Destroy;
end;
Saludos