Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



Share:
Notifications
Clear all

[Solved] Delphi/Lazarus - Rotate TBitmap 180 degrees

1 Posts
1 Users
0 Reactions
3,186 Views
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2869
Topic starter  

The following procedure rotates a TBitmap 180 degrees:

procedure Rotate180(Bitmap:TBitmap);
type TRGBArray = array[0..0] of TRGBTriple;
pRGBArray = ^TRGBArray;
var countRows, countColumns: integer;
rowIn,rowOut:
pRGBArray;
tmpBitmap: TBitmap;
begin
// Create tmp bitmap
tmpBitmap:=TBitmap.Create;
// Adjust tmp bitmap size and pixelformat
with tmpBitmap do
begin
Width:=Bitmap.Width;
Height:=Bitmap.Height;
PixelFormat:=Bitmap.PixelFormat;
end;
// Use scanline to copy pixels from rowin to rowout in reverse order
for countRows:=0to Bitmap.Height-1 do
begin
rowIn:=Bitmap.ScanLine[countRows];
rowOut:=tmpBitmap.ScanLine[Bitmap.Height-countRows-1];

for countColumns:=0 to Bitmap.Width-1 do
rowOut[Bitmap.Width-countColumns-1]:=rowIn[countColumns];
end;
// Copy bitmap to source and free tmp bitmap
bitmap.assign(tmpBitmap);
tmpBitmap.free;
end;


   
ReplyQuote
Share: