Thema: Delphi bmp drehen

Einzelnen Beitrag anzeigen

arukas

Registriert seit: 14. Mär 2006
40 Beiträge
 
#6

Re: bmp drehen

  Alt 15. Mär 2006, 16:02
hi,

ich hab noch mal eine Frage.

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    image: TImage;
    procedure Button1Click(Sender: TObject);
FUNCTION Rotate(CONST BitmapOriginal: TBitmap;
  CONST iRotationAxis, jRotationAxis: INTEGER;
  CONST AngleOfRotation: DOUBLE {radians} ): TBitmap;
  private
    { Private declarations }
  public
    { Public declarations }
  end;


CONST
MaxPixelCount = 32768;

TYPE
  TRGBTripleArray = ARRAY[0..MaxPixelCount-1] OF TRGBTriple;
  pRGBTripleArray = ^TRGBTripleArray;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
rotate(image,12,34,56);

end;


// "Simple" approach. For pixel (i,j), use "reverse" rotation to find
// where the rotated pixel must have been before the rotation.
// Don't bother with center of pixel adjustment.
// Assumes input BitmapOriginal has PixelFormat = pf24bit.
FUNCTION Rotate(CONST BitmapOriginal: TBitmap;
  CONST iRotationAxis, jRotationAxis: INTEGER;
  CONST AngleOfRotation: DOUBLE {radians} ): TBitmap;

  VAR
    cosTheta : EXTENDED;
    i : INTEGER;
    iOriginal : INTEGER;
    iPrime : INTEGER;
    j : INTEGER;
    jOriginal : INTEGER;
    jPrime : INTEGER;
    RowOriginal: pRGBTripleArray;
    RowRotated : pRGBTRipleArray;
    sinTheta : EXTENDED;
BEGIN
  // The size of BitmapRotated is the same as BitmapOriginal. PixelFormat
  // must also match since 24-bit GBR triplets are assumed in ScanLine.
  RESULT := TBitmap.Create;
  RESULT.Width := BitmapOriginal.Width;
  RESULT.Height := BitmapOriginal.Height;
  RESULT.PixelFormat := pf24bit; // Force this

  // Get SIN and COS in single call from math library
  sinTheta := SIN(AngleOfRotation);

  // If no math library, then use this:
  // sinTheta := SIN(AngleOfRotation);
  // cosTheta := COS(AngleOfRotation);

  // Step through each row of rotated image.
  FOR j := RESULT.Height-1 DOWNTO 0 DO
  BEGIN
    RowRotated := RESULT.Scanline[j];
    jPrime := j - jRotationAxis;

    FOR i := RESULT.Width-1 DOWNTO 0 DO
    BEGIN
      iPrime := i - iRotationAxis;
      iOriginal := iRotationAxis + ROUND(iPrime * CosTheta - jPrime * sinTheta);
      jOriginal := jRotationAxis + ROUND(iPrime * sinTheta + jPrime * cosTheta);

      // Make sure (iOriginal, jOriginal) is in BitmapOriginal. If not,
      // assign blue color to corner points.
      IF (iOriginal >= 0) AND (iOriginal <= BitmapOriginal.Width-1) AND
          (jOriginal >= 0) AND (jOriginal <= BitmapOriginal.Height-1)
      THEN BEGIN
        // Assign pixel from rotated space to current pixel in BitmapRotated
        RowOriginal := BitmapOriginal.Scanline[jOriginal];
        RowRotated[i] := RowOriginal[iOriginal]
      END
      ELSE BEGIN
        RowRotated[i].rgbtBlue := 255; // assign "corner" color
        RowRotated[i].rgbtGreen := 0;
        RowRotated[i].rgbtRed := 0
     END

    END
  END
END {RotateBitmapMethod1};



end.
Bei dem Code bekomme ich folgende Fehlermeldung:

Delphi-Quellcode:
[Error] Unit1.pas(40): Incompatible types: 'TBitmapand 'TImage'
[Error] Unit1.pas(14): Unsatisfied forward or external declaration: 'TForm1.Rotate'
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
Ich dachte eigentlich, dass ich hier...
Delphi-Quellcode:
rotate(image,12,34,56);
.
.
FUNCTION Rotate(CONST BitmapOriginal: TBitmap;
CONST iRotationAxis, jRotationAxis: INTEGER;
CONST AngleOfRotation: DOUBLE {radians} ): TBitmap;
...nur sagen muss, welches Bild ich wie drehen möchte, aber irgendwie scheint das nicht ganz so gut zu funktionieren, wie ich mir das vorgestellt hab.

pls help


Euer Arukas
  Mit Zitat antworten Zitat