Vertical mirror (Using ScanLine)  

Send By: Radikal (Q3 Team)
Web : http://www.q3.nu
Email: radikal@q3.nu
Date: 10/02/00

Tip accessed 478 times

 


There is already a tip to make vertical mirror in a bitmap, in short the tip:

[259] - Vertical mirror in a Bitmap

Here I offer you other that instead of using TBitmap.Canvas.Pixels to access to the data of the image, ScanLine uses, winning this way in speed.:


 procedure TForm1.Button1Click(Sender: TObject);

   procedure EspejoVertical(Origen,Destino:TBitmap);
   var
      x,y          : integer;
      Alto         : integer;
      Po,Pd        : PByteArray;
      tmpBMP       : TBitmap;
      LongScan     : integer;
   begin
     {Si es un modo raro... pasamos}
     case Origen.PixelFormat of
       pfDevice,
       pfCustom:
         Raise exception.create( 'Formato no soportado'+#13+
                                 'Bitmap Format not valid');
     end;

     {Calculamos variables intermedias}
     Alto :=Image1.Picture.Bitmap.Height-1;
     try
       {Calculo de cuánto ocupa un scan}
       LongScan:= Abs( Integer(Origen.ScanLine[0])-
                       Integer(Origen.ScanLine[1]) );
     except
       Raise exception.create( 'ScanLine Error...');
     end;

     {Cremos un bitmap intermedio}
     tmpBMP:=TBitmap.Create;
     with tmpBMP do
     begin
       {Lo asignamos, así se copia la paleta si la hay}
       Assign(Origen);
       {Esto es para que sea un bitmap nuevo... es un bug de D3 y D4}
       Canvas.Pixels[0,0]:=Origen.Canvas.Pixels[0,0];
     end;

     {Damos la vuelta al bitmap}
     for y:=0 to Alto do
     begin
       Po := Origen.ScanLine[y];
       Pd := tmpBMP.ScanLine[Alto-y];
       for x := 0 to LongScan-1 do
       begin
           Pd^[X]:=Po^[X];
       end;
     end;
     {Lo asignamos al bitmap destino}
     Destino.Assign(tmpBMP);
     {Esto es para parchear un bug de Delphi 3 y Delphi4...}
     Destino.Canvas.Pixels[0,0]:=tmpBMP.Canvas.Pixels[0,0];
     tmpBMP.Free;
   end;
 begin
   EspejoVertical( Image1.Picture.Bitmap,
                   Image1.Picture.Bitmap);
   Image1.Refresh;
 end;




Updated at 10/02/2000 (for x := 0 to LongScan-1 do)