DelphiFAQ Home Search:
General :: Windows :: Programming :: Windows with Delphi :: Windows Graphics
Graphics programming under Windows with Delphi.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

How to flip a bitmap image

Question:
Is there a RTL or API function to flip a bitmap image?

Answer:

You can use the Windows function StrechBlt() to help you with this. Some older versions of Windows (Windows 3.1, Windows 95) had problems with the graphic card drivers for these functions.
I myself had a Diamond Stealth (or was it a Diamond Speedstar?) where this Windows function was not implemented properly in the Windows 95 driver. There is another Win API function for it.. for device independant bitmaps - it is called StretchDIBits(), but StretchBlt() is faster.

And nowadays (June 2004), all graphic cards should be supported properly.

type
   TMirror = (mtHorizontal, mtVertical, mtBoth );
 
 procedure Mirror(Picture: TPicture; MirrorType: TMirror);
 var
   MemBmp: Graphics.TBitmap;
   Dest: TRect;
 begin { Mirror }
   if Assigned(Picture.Graphic) then
   begin
     MemBmp := Graphics.TBitmap.Create;
     try
       MemBmp.PixelFormat := pf24bit;
       MemBmp.HandleType := bmDIB;
       MemBmp.Width := Self.Picture.Graphic.Width;
       MemBmp.Height := Self.Picture.Height;
       MemBmp.Canvas.Draw(0, 0, Picture.Graphic);
 
       case MirrorType of
         mtHorizontal:
           begin
             //SpiegelnVertikal(MemBmp);
             //SpiegelnHorizontal(MemBmp);
             Dest.Left := MemBmp.Width;
             Dest.Top := 0;
             Dest.Right := -MemBmp.Width;
             Dest.Bottom := MemBmp.Height
           end;
         mtVertical:
           begin
             Dest.Left := 0;
             Dest.Top := MemBmp.Height;
             Dest.Right := MemBmp.Width;
             Dest.Bottom := -MemBmp.Height
           end;
         mtBoth:
           begin
             Dest.Left := MemBmp.Width;
             Dest.Top := MemBmp.Height;
             Dest.Right := -MemBmp.Width;
             Dest.Bottom := -MemBmp.Height
           end;
       end; { case MirrorType }
       StretchBlt(MemBmp.Canvas.Handle, Dest.Left, Dest.Top, Dest.Right, Dest.Bottom,
                  MemBmp.Canvas.Handle, 0, 0, MemBmp.Width, MemBmp.Height,
                  SRCCOPY);
 
       Picture.Graphic.Assign(MemBmp);
       Invalidate
     finally
       FreeAndNil(MemBmp)
     end; { try }
   end; { Assigned(Picture.Graphic) }
 end; { Mirror }
 
You don't like the formatting? Check out SourceCoder then!
Generated 8:03:29 on Oct 21, 2018