垂直反転

画像を垂直方向に反転させます。作業用に同サイズの画像を用意してラインをコピーしていく方法でもいいのですが、ここでは一ライン分のバッファを用意してラインの入れ替えを行う方法を使います。

procedure VertReverse(Source: TBitmap);
var
  Y, H, BufSize: Integer;
  pLine1, pLine2, pBuffer: Pointer;
begin
  Source.PixelFormat := pf24bit;
  BufSize := BytesPerScanline(Source.Width, 24, 32);
  H := Source.Height -1;
  GetMem(pBuffer, BufSize);
  try
    with Source do
      for Y := 0 to H div 2 do
      begin
        pLine1 := ScanLine[Y];
        pLine2 := ScanLine[H-Y];
        Move(pLine1^, pBuffer^, BufSize);
        Move(pLine2^, pLine1^, BufSize);
        Move(pBuffer^, pLine2^, BufSize);
      end;
  finally
    FreeMem(pBuffer);
  end;
  if Assigned(Source.OnChange) then
    Source.OnChange(Source);
end;

Copyright 2001 Rinka Kouzuki All Rights Reserved.