![]() |
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 ![]() |
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 |
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; |
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. ;)
|
Re: Mathematik, gedrehtes Bild an Rahmen anpassen
So, ich habe das mal ausprobiert:
Delphi-Quellcode:
Aber ich bekomme beim Aufrufen der Prozedur immer eine AccessViolation. Wende ich die Prozedur RotateBitmap falsch an?
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; |
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 :) |
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; |
Re: Mathematik, gedrehtes Bild an Rahmen anpassen
|
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. |
Re: Mathematik, gedrehtes Bild an Rahmen anpassen
Zitat:
Zitat:
Gruß Hawkeye |
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:43 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz