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 90 degrees

1 Posts
1 Users
0 Likes
4,596 Views
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2697
Topic starter  

The following code will rotate a Bitmap 90 degrees counter clockwise:

procedure TForm3.Rotate90(Bitmap:TBitmap);
type TRGBArray = array[0..0] of TRGBTriple;
pRGBArray = ^TRGBArray;
var oldRows,
oldColumns: integer;
rowIn,rowOut:
pRGBArray;
tmpBitmap: TBitmap;
begin
// Create tmp bitmap
tmpBitmap:=TBitmap.Create;
// Adjust tmp bitmap size and pixelformat (rotate 90 = W-> and H->W)
with tmpBitmap do
begin
tmpBitmap.Width:=Bitmap.Height;
tmpBitmap.Height:=Bitmap.Width;
tmpBitmap.PixelFormat:=Bitmap.PixelFormat;
end;

for oldColumns := 0 to Bitmap.Width - 1 do // oldColumns=newRows, oldRows=newColumns
begin
rowOut:=tmpBitmap.ScanLine[oldColumns];
// Fastest way is reading bit, so we work on one line in the new bitmap ata time
for oldRows:= 0 to Bitmap.Height - 1 do
begin
rowIn:=Bitmap.ScanLine[oldRows];
rowOut[oldRows]:=rowIn[Bitmap.Width - oldColumns -1];
end;
end;

// Copy bitmap to source and free tmp bitmap
bitmap.assign(tmpBitmap);
tmpBitmap.free;
end;


   
ReplyQuote
Share: