Forum
Grundkurs
»Introduktion
»Snabbguide
»Komponenter
»Händelser
»Strängar
»Räkna med Delphi »Egna
typer
»Selektion
»Iteration
»Menyer
»Funktioner
»Arraystrukturer
Tips & Tricks
»Nya tips
»Blandat
»Databaser
»Filer
»Forms
»Grafik
»Internet
»Komponenter
»Matematik
»Multimedia
»Objekt/ActiveX
»Skrivare
»Strängar
»System
»Mest lästa tips
Artiklar
»Delphi och ADO
»Bygga en DLL
»Skapa en enkel rapport
»Hantera registret
»Enheter, units
»Klassen TCanvas
»Använd LookUp Controls
Nya
tips
Lägg
till tips
Delphilänkar
Gästbok
|
|
|
|
Rotera en bitmap (i valfri vinkel och rotationscentrering)
|
Kategori: Grafik
Inlagt: 2005-01-04
Läst: 1390
Inlagt av: Staffan Berg
|
Beskrivning |
Med denna procedur kan du rotera en bitmap med några olika inställningsmöjligheter.
|
Kod |
const PixelMax = 32768; type pPixelArray = ^TPixelArray; TPixelArray = Array[0..PixelMax-1] Of TRGBTriple; procedure RotateBitmap_ads( SourceBitmap : TBitmap; out DestBitmap : TBitmap; Center : TPoint; Angle : Double) ; var cosRadians : Double; inX : Integer; inXOriginal : Integer; inXPrime : Integer; inXPrimeRotated : Integer; inY : Integer; inYOriginal : Integer; inYPrime : Integer; inYPrimeRotated : Integer; OriginalRow : pPixelArray; Radians : Double; RotatedRow : pPixelArray; sinRadians : Double; begin DestBitmap.Width := SourceBitmap.Width; DestBitmap.Height := SourceBitmap.Height; DestBitmap.PixelFormat := pf24bit; Radians := -(Angle) * PI / 180; sinRadians := Sin(Radians) ; cosRadians := Cos(Radians) ; for inX := DestBitmap.Height-1 Downto 0 Do begin RotatedRow := DestBitmap.Scanline[inX]; inXPrime := 2*(inX - Center.y) + 1; for inY := DestBitmap.Width-1 Downto 0 Do begin inYPrime := 2*(inY - Center.x) + 1; inYPrimeRotated := Round(inYPrime * CosRadians - inXPrime * sinRadians) ; inXPrimeRotated := Round(inYPrime * sinRadians + inXPrime * cosRadians) ; inYOriginal := (inYPrimeRotated - 1) Div 2 + Center.x; inXOriginal := (inXPrimeRotated - 1) Div 2 + Center.y; if (inYOriginal >= 0) And (inYOriginal <= SourceBitmap.Width-1) And (inXOriginal >= 0) And (inXOriginal <= SourceBitmap.Height-1) then begin OriginalRow := SourceBitmap.Scanline[inXOriginal]; RotatedRow[inY] := OriginalRow[inYOriginal] end else begin RotatedRow[inY].rgbtBlue := 255; RotatedRow[inY].rgbtGreen := 0; RotatedRow[inY].rgbtRed := 0 end; end; end; end; //Usage: procedure TForm1.Button1Click(Sender: TObject) ; var Center : TPoint; Bitmap : TBitmap; begin Bitmap := TBitmap.Create; try Center.y := (Image.Height div 2)+20; Center.x := (Image.Width div 2)+0; RotateBitmap_ads( Image.Picture.Bitmap, Bitmap, Center, Angle) ; Angle := Angle + 15; Image2.Picture.Bitmap.Assign(Bitmap) ; finally Bitmap.Free; end; end;
|
|
|