Registriert seit: 29. Mai 2002
37.621 Beiträge
Delphi 2006 Professional
|
Re: Mathematik, gedrehtes Bild an Rahmen anpassen
20. Feb 2007, 12:43
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;
Michael Ein Teil meines Codes würde euch verunsichern.
|
|
Zitat
|