Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Mathematik, gedrehtes Bild an Rahmen anpassen (https://www.delphipraxis.net/82390-mathematik-gedrehtes-bild-rahmen-anpassen.html)

Luckie 12. Dez 2006 12:34


Mathematik, gedrehtes Bild an Rahmen anpassen
 
Liste der Anhänge anzeigen (Anzahl: 1)
Ich habe ein kleines mathematisches-multimedia Problem.

Und zwar drehe ich in einem Layer / Rahmen ein Bild. Jetzt wird es nur bei jedem Drehen kleiner. Siehe dazu das Bild im Anhang. Ich kann das Bild aber nach dem Drehen wieder vergrößern, hoffe ich. Aber wie bekomme ich die neue Höhe und Breite raus, damit es mit seinen Ecken wieder an den Rahmen stößt?

Ich benutze die ImagenEn Komponenten von HiComponents. Wer mit diesen Komponenten eine Lösung weiß, ohne dass ich das Bild von Hand in der Größe anpassen muss, darf das hier auch ruhig zum Besten geben. ;)

flossinger 17. Dez 2006 15:56

Re: Mathematik, gedrehtes Bild an Rahmen anpassen
 
Das gedrehte Bild ist auch völlig verzerrt. Es ist nicht mehr rechtwinkelig. Zumindest dieht es auf meinem Bildschirm so aus. Möglicherweise ist der Algorithmus falsch, oder ist mit falschen Daten versorgt worden. Leider kenne ich die Komponenten nicht. Von der Grössenordnung her könnte der Grössenfehler und der Winkelfehler etwas miteinander zu tun haben.

Grüsse,
der flossinger

supermuckl 17. Dez 2006 16:03

Re: Mathematik, gedrehtes Bild an Rahmen anpassen
 
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;

Luckie 17. Dez 2006 21:29

Re: Mathematik, gedrehtes Bild an Rahmen anpassen
 
Ui, da muss ich mal gucken, wie ich das mit der Komponente verbinden kann. Aber besten Dank schon mal. Da habe ich morgen ja wieder was zu tun. ;)

Luckie 18. Dez 2006 11:41

Re: Mathematik, gedrehtes Bild an Rahmen anpassen
 
So, ich habe das mal ausprobiert:
Delphi-Quellcode:
var
  BmpSrc, BmpDest  : TBitmap;
begin
  BmpSrc := TBitmap.Create;
  BmpDest := TBitmap.Create;
  try
    BmpSrc.Width := ImageEnVect1.layers[ImageEnVect1.LayersCurrent].Width;
    BmpSrc.Height := ImageEnVect1.layers[ImageEnVect1.LayersCurrent].Height;
    BmpDest.Width := ImageEnVect1.layers[ImageEnVect1.LayersCurrent].Width;
    BmpDest.Height := ImageEnVect1.layers[ImageEnVect1.LayersCurrent].Height;
    BmpSrc.Assign(ImageEnVect1.Bitmap);
    RotateBitmap(BmpSrc, BmpDest, 10.0);
    ImageEnVect1.Bitmap.Assign(BmpDest);
  finally
    BmpSrc.Free;
    BmpDest.Free;
  end;
Aber ich bekomme beim Aufrufen der Prozedur immer eine AccessViolation. Wende ich die Prozedur RotateBitmap falsch an?

supermuckl 18. Dez 2006 15:15

Re: Mathematik, gedrehtes Bild an Rahmen anpassen
 
so rufe ich in meinem alten projekt diese funktion auf:

Delphi-Quellcode:
rotatebitmap(zwischenbitmap2,tmpbmp2R,degtorad(sprite2.Rotation));

Sprite_1,Sprite_2:TglSprite

der winkel sollte also in grad sein
die funktion frisst dann wohl rad statt grad und deshalb die degtorad :)

Luckie 20. Feb 2007 11:43

Re: Mathematik, gedrehtes Bild an Rahmen anpassen
 
Ich bekomme bei dem Code immer noch eine AV:
Delphi-Quellcode:
procedure TForm2.tbbRotateLeftClick(Sender: TObject);

  procedure 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;

var
  BmpSrc, BmpDest  : TBitmap;
begin
  BmpSrc := TBitmap.Create;
  BmpDest := TBitmap.Create;
  try
    BmpSrc.Width := ImageEnVect1.layers[ImageEnVect1.LayersCurrent].Width;
    BmpSrc.Height := ImageEnVect1.layers[ImageEnVect1.LayersCurrent].Height;
    BmpDest.Width := ImageEnVect1.layers[ImageEnVect1.LayersCurrent].Width;
    BmpDest.Height := ImageEnVect1.layers[ImageEnVect1.LayersCurrent].Height;
    BmpSrc.Assign(ImageEnVect1.Bitmap);
    RotateBitmap(BmpSrc, BmpDest, DegToRad(10));
    ImageEnVect1.Bitmap.Assign(BmpDest);
  finally
    BmpSrc.Free;
    BmpDest.Free;
  end;
end;

Hawkeye219 20. Feb 2007 12:07

Re: Mathematik, gedrehtes Bild an Rahmen anpassen
 
Hallo Michael,

hier ist eine alternative Routine zum Drehen eines Bildes: klick

Gruß Hawkeye

Luckie 20. Feb 2007 12:31

Re: Mathematik, gedrehtes Bild an Rahmen anpassen
 
Wo kommen da die ganzen Funktionen her: SetGraphicsMode, GetWorldTransform, SetWorldTransform, ModifyWorldTransform usw. ?

Desweiteren kann ich nur ein Bitmap übergeben. Ein Objekt vom Typ TGraphic habe ich nicht zur Verfügung.

Hawkeye219 20. Feb 2007 12:39

Re: Mathematik, gedrehtes Bild an Rahmen anpassen
 
Zitat:

Zitat von Luckie
Wo kommen da die ganzen Funktionen her: SetGraphicsMode, GetWorldTransform, SetWorldTransform, ModifyWorldTransform usw. ?

Das sind GDI-Routinen (windows.pas).

Zitat:

Desweiteren kann ich nur ein Bitmap übergeben. Ein Objekt vom Typ TGraphic habe ich nicht zur Verfügung.
Für TBitmaps kannst du die Routine aus Beitrag #9 des Threads verwenden.

Gruß Hawkeye


Alle Zeitangaben in WEZ +1. Es ist jetzt 02:51 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz