Rotate a Bitmap 90 degree anticlockwise  

Send By: Q3 Team
Web : http://www.q3.nu
Email: dlib@q3.nu
Date: 04/01/00

Tip accessed 546 times

 


  • Put a TButton (Button1) and a TImage (Image1) in your form
  • Load an image in Image1


     procedure TForm1.Button1Click(Sender: TObject);
    
     procedure RotarAntiH(BMPOrigen, BMPDestino:TBitmap);
     var
        f,c:integer;
        Ancho,Alto:integer;
        tmpBMP: TBitmap;
     begin
       {Bitmap temporal}
       tmpBMP:=TBitmap.create;
       with tmpBMP do
       begin
         Width:=BMPOrigen.height;
         Height :=BMPOrigen.width;
       end;
    
       {Inicializamos los límites de los bucles}
       {Initialize loop's limits}
       Ancho:=BMPOrigen.Width-1;
       Alto :=BMPOrigen.Height-1;
    
       {Copiamos los pixels}
       {Copy the pìxels}
       for f:=0 to Alto do
       begin
         for c:=0 to Ancho do
         begin
           tmpBMP.Canvas.Pixels[f,Ancho-c]:=BMPOrigen.Canvas.Pixels[c,f];
           Application.processmessages;
         end;
    
       end;
    
       BMPDestino.Assign(tmpBMP);
       tmpBMP.Free;
     end;
    
     begin
       RotarAntiH(Image1.Picture.Bitmap,Image1.Picture.Bitmap);
     end;
    



    You can use the function with the same Bitmap like origin and like destination or to put the resulting image in another bitmap.