|
Flipping an Image or rotating it 90°
{these functions assume BitMap : TBitMap
is a data member of Form1;
a similiar function can be used to rotate
an image 180° or 270°}
procedure TForm1.Rotate90;
var
x, y : cardinal;
BitMap2 : TBitMap;
begin
BitMap2 := TBitMap.Create;
with BitMap do begin
BitMap2.Width := Height;
BitMap2.Height := Width;
for y := 0 to Height - 1 do
for x := 0 to Width - 1 do
BitMap2.Canvas.Pixels[y, Width - x - 1] := Canvas.Pixels[x, y];
Assign (BitMap2);
end;//with...
end;
{this procedure basically swaps each pixel
on the left half of the BitMap with a correspond
pixel on the right half; a similiar function
could flip vertically}
procedure TForm1.FlipHorz;
var
x, y : cardinal;
HColor : TColor;
begin
with BitMap do
for y := 0 to Height - 1 do
for x := 0 to Width div 2 do begin
HColor := Canvas.Pixels[x, y];
Canvas.Pixels[x, y] := Canvas.Pixels[Width - x - 1, y];
Canvas.Pixels[Width - x - 1, y ] := HColor;
end;
end;
|