Einzelnen Beitrag anzeigen

supermuckl

Registriert seit: 1. Feb 2003
1.340 Beiträge
 
FreePascal / Lazarus
 
#3

Re: Mathematik, gedrehtes Bild an Rahmen anpassen

  Alt 17. Dez 2006, 17:03
probier mal das:

Delphi-Quellcode:
procedure Tform1.RotateBitmap(CONST BitmapOriginal: TBitmap; BitmapRotated: TBitmap; CONST AngleOfRotation: DOUBLE );
  VAR
    jRotationAxis : INTEGER;
    iRotationAxis : INTEGER;
    cosTheta : EXTENDED;
    i : INTEGER;
    iOriginal : INTEGER;
    iPrime : INTEGER;
    j : INTEGER;
    jOriginal : INTEGER;
    jPrime : INTEGER;
    RowOriginal : PRGB32Array;
    RowRotated : PRGB32Array;
    sinTheta : EXTENDED;
begin
iRotationAxis := BitmapOriginal.Width div 2;
jRotationAxis := BitmapOriginal.height div 2;
  // Get SIN and COS in single call from math library
  sincos(AngleOfRotation, sinTheta, cosTheta);

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

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

    FOR i := BitmapRotated.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 transparent 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].R := 0; // assign transparent color
        RowRotated[i].G := 0;
        RowRotated[i].B := 0
      END

    END
  END;

END;
Das echte Leben ist was für Leute...
... die im Internet keine Freunde finden!
  Mit Zitat antworten Zitat