Recent

Author Topic: [SHARE] Rotate and Flip bitmap  (Read 336 times)

Xenno

  • Jr. Member
  • **
  • Posts: 62
    • BS Programs
[SHARE] Rotate and Flip bitmap
« on: February 10, 2026, 07:37:56 am »
For anyone who's been looking and my repository.
Note: Microsoft Windows

Cheers,

Code: Pascal  [Select][+][-]
  1. uses Windows, Graphics;
  2.  
  3. procedure PrcRotateBitmapRight(PrmBmp1, PrmBmp2: TBitmap);
  4. var
  5.   x1, y1, x2, y2: Integer;
  6.   p: array[0..2] of TPoint;
  7. begin
  8.   x1 := 0;
  9.   y1 := 0;
  10.   x2 := PrmBmp1.Width;
  11.   y2 := PrmBmp1.Height;
  12.  
  13.   PrmBmp2.Width := y2;
  14.   PrmBmp2.Height := x2;
  15.  
  16.   p[0].X := y2;
  17.   p[0].Y := x1;
  18.   p[1].X := y2;
  19.   p[1].Y := x2;
  20.   p[2].X := y1;
  21.   p[2].Y := x1;
  22.  
  23.   PlgBlt(PrmBmp2.Canvas.Handle, p, PrmBmp1.Canvas.Handle, 0, 0, x2, y2, 0, 0, 0);
  24. end;
  25.  
  26.  
  27. procedure PrcRotateBitmapLeft(PrmBmp1, PrmBmp2: TBitmap);
  28. var
  29.   x1, y1, x2, y2: Integer;
  30.   p: array[0..2] of TPoint;
  31. begin
  32.   x1 := 0;
  33.   y1 := 0;
  34.   x2 := PrmBmp1.Width;
  35.   y2 := PrmBmp1.Height;
  36.  
  37.   PrmBmp2.Width := y2;
  38.   PrmBmp2.Height := x2;
  39.  
  40.   p[0].X := y1;
  41.   p[0].Y := x2;
  42.   p[1].X := y1;
  43.   p[1].Y := x1;
  44.   p[2].X := y2;
  45.   p[2].Y := x2;
  46.  
  47.   PlgBlt(PrmBmp2.Canvas.Handle, p, PrmBmp1.Canvas.Handle, 0, 0, x2, y2, 0, 0, 0);
  48. end;
  49.  
  50.  
  51. procedure PrcFlipBitmapVert(PrmBmp: TBitmap);
  52. var
  53.   Bmp: TBitmap;
  54.   SourceRect, DestRect: TRect;
  55. begin
  56.   Bmp := TBitmap.Create;
  57.   try
  58.     Bmp.Assign(PrmBmp);
  59.     DestRect := Rect(0, 0, PrmBmp.Width, PrmBmp.Height);
  60.     SourceRect := Rect(0, PrmBmp.Height - 1, PrmBmp.Width, -1);
  61.     PrmBmp.Canvas.CopyRect(DestRect, Bmp.Canvas, SourceRect);
  62.   finally
  63.     Bmp.Free;
  64.   end;
  65. end;
  66.  
  67.  
  68. procedure PrcFlipBitmapHorz(PrmBmp: TBitmap);
  69. var
  70.   Bmp: TBitmap;
  71.   SourceRect, DestRect: TRect;
  72. begin
  73.   Bmp := TBitmap.Create;
  74.   try
  75.     Bmp.Assign(PrmBmp);
  76.     DestRect := Rect(0, 0, Bmp.Width, Bmp.Height);
  77.     SourceRect := Rect(Bmp.Width - 1, 0, -1, Bmp.Height);
  78.     PrmBmp.Canvas.CopyRect(DestRect, Bmp.Canvas, SourceRect);
  79.   finally
  80.     Bmp.Free;
  81.   end;
  82. end;
   
Lazarus 4.0, Windows 10, https://www.youtube.com/@bsprograms

 

TinyPortal © 2005-2018