Re: How to rotate a bitmap?
- From: "Heinrich Wolf" <invalid@xxxxxxxxxxxxxxx>
- Date: Sun, 12 Jun 2005 10:31:47 +0200
Hi,
here is my code. It is german. Some translations:
german - english
Drehen - Rotate
Winkel - Angle
Fortschritt - Progress
MussSpeichern - MustSave
Function GaussTrunc(r : Extended) : Integer;
Begin
If r < 0 Then
GaussTrunc := Pred(Trunc(r))
Else
GaussTrunc := Trunc(r);
End;
Function GaussRound(r : Extended) : Integer;
Begin
GaussRound := GaussTrunc(r + 0.5);
End;
procedure TMainForm.Drehen(xFaktorX, xFaktorY, yFaktorX, yFaktorY : real;
Aktion : String);
var x, y,
xMin,
xMax,
yMin,
yMax,
xHidden,
yHidden : LongInt;
xx, xy : Real;
yx, yy : Array of Real;
begin
Enable(False);
xMin := 0;
xMax := 0;
yMin := 0;
yMax := 0;
x := GaussRound( (VisibleImage.Picture.Bitmap.Width - 1) * xFaktorX
+ (VisibleImage.Picture.Bitmap.Height - 1) *
yFaktorX);
y := GaussRound( (VisibleImage.Picture.Bitmap.Width - 1) * xFaktorY
+ (VisibleImage.Picture.Bitmap.Height - 1) *
yFaktorY);
if x < xMin then
xMin := x;
if x > xMax then
xMax := x;
if y < yMin then
yMin := y;
if y > yMax then
yMax := y;
x := GaussRound((VisibleImage.Picture.Bitmap.Width - 1) * xFaktorX);
y := GaussRound((VisibleImage.Picture.Bitmap.Width - 1) * xFaktorY);
if x < xMin then
xMin := x;
if x > xMax then
xMax := x;
if y < yMin then
yMin := y;
if y > yMax then
yMax := y;
x := GaussRound((VisibleImage.Picture.Bitmap.Height - 1) * yFaktorX);
y := GaussRound((VisibleImage.Picture.Bitmap.Height - 1) * yFaktorY);
if x < xMin then
xMin := x;
if x > xMax then
xMax := x;
if y < yMin then
yMin := y;
if y > yMax then
yMax := y;
HiddenImage.Picture.Bitmap.Width := xMax - xMin + 1;
HiddenImage.Picture.Bitmap.Height := yMax - yMin + 1;
HiddenImage.Picture.Bitmap.Canvas.Brush.Style := bsSolid;
HiddenImage.Picture.Bitmap.Canvas.Brush.Color := clWhite;
HiddenImage.Picture.Bitmap.Canvas.FillRect(
Rect(0, 0, HiddenImage.Picture.Bitmap.Width,
HiddenImage.Picture.Bitmap.Height));
SetLength(yx, VisibleImage.Picture.Bitmap.Height);
SetLength(yy, VisibleImage.Picture.Bitmap.Height);
for y := 0 to VisibleImage.Picture.Bitmap.Height - 1 do
begin
yx[y] := y * yFaktorX;
yy[y] := y * yFaktorY;
end;
FortschrittForm.Start(clWhite, clBlue, Aktion);
x := 0;
while (x < VisibleImage.Picture.Bitmap.Width)
and FortschrittForm.Continue(
(x * 100) div (VisibleImage.Picture.Bitmap.Width - 1)) do
begin
xx := x * xFaktorX;
xy := x * xFaktorY;
y := 0;
while (y < VisibleImage.Picture.Bitmap.Height)
and FortschrittForm.Continue(
(x * 100) div (VisibleImage.Picture.Bitmap.Width - 1))
do
begin
xHidden := GaussRound(xx + yx[y]) - xMin;
yHidden := GaussRound(xy + yy[y]) - yMin;
HiddenImage.Picture.Bitmap.Canvas.Pixels[xHidden, yHidden]
:=
VisibleImage.Picture.Bitmap.Canvas.Pixels[x, y];
HiddenImage.Picture.Bitmap.Canvas.Pixels[xHidden + 1, yHidden]
:=
VisibleImage.Picture.Bitmap.Canvas.Pixels[x, y];
HiddenImage.Picture.Bitmap.Canvas.Pixels[xHidden, yHidden +
1] :=
VisibleImage.Picture.Bitmap.Canvas.Pixels[x, y];
inc(y);
end;
inc(x);
end;
if FortschrittForm.Complete then
begin
VisibleImage.Height := HiddenImage.Picture.Bitmap.Height;
VisibleImage.Width := HiddenImage.Picture.Bitmap.Width;
VisibleImage.Picture.Bitmap.Assign(HiddenImage.Picture.Bitmap);
MussSpeichern := True;
end;
Enable(True);
end;
procedure TMainForm.MnuDrehenClick(Sender: TObject);
var w : real;
begin
ParamForm.Param.Caption := 'Winkel';
ParamForm.SpinEdit.MinValue := -179;
ParamForm.SpinEdit.MaxValue := 180;
ParamForm.SpinEdit.Value := 90;
if ParamForm.ShowModal = mrOk then
if ParamForm.SpinEdit.Value <> 0 then
begin
w := ParamForm.SpinEdit.Value * arctan(1) / 45;
Drehen( cos(w), sin(w),
-sin(w), cos(w), 'Drehen');
end;
end;
.
- Follow-Ups:
- Re: How to rotate a bitmap?
- From: Heinrich Wolf
- Re: How to rotate a bitmap?
- References:
- How to rotate a bitmap?
- From: Brent W. Hughes
- How to rotate a bitmap?
- Prev by Date: Re: How to rotate a bitmap?
- Next by Date: Re: Where is the profit?
- Previous by thread: Re: How to rotate a bitmap?
- Next by thread: Re: How to rotate a bitmap?
- Index(es):
Relevant Pages
|