Bonjour à tous
J'essaie de faire pivoter une image de 90°.
Je me suis inspiré d'un bout de code ( https://www.developpez.net/forums/d1...calees-d-1-px/ )

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  BGRABitmap, BGRABitmapTypes;
type
 
  { TForm1 }
 
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure dessin();
  private
    procedure RotateImage(src, dest: TBGRABitmap; rot: Integer);
  public
  end;
 
var
  Form1: TForm1;
 
implementation
{$R *.lfm}
procedure TForm1.dessin();
var
  iSrc, iDest: TBGRABitmap;
begin
   iSrc := TBGRABitmap.Create('d:\a.png');  //image qui fait 800*600
  try
    iDest := TBGRABitmap.Create(iSrc.Height, iSrc.Width);   //image destination pour rotation 90°
 
    try
      // rotations et dessin sur le canevas final
 
      RotateImage(iSrc, iDest, 90);    // rotation 90°
     iDest.Draw(Canvas, 100, 10);
        idest.SaveToFile('d:\new_a.png');
 
    finally
      iDest.Free;
    end;
  finally
    iSrc.Free;
  end;
end;
 
procedure TForm1.Button1Click(Sender: TObject);
begin
 dessin;
end;
 
procedure TForm1.RotateImage(src, dest: TBGRABitmap; rot: Integer);
// rotation d'une image : 1 = 0 / 2 = 90 / 3 = 180 / 4 = 270
var
  Tmp: TBGRABitmap;
begin
  Tmp := TBGRABitmap.Create(Src.Width,Src.Height, BGRAblack);
  try
    tmp.PutImageAngle(src.Width/2,
                    src.Height/2,
                    src,
                    rot,
                    tmp.Width/2,
                    tmp.Height/2);
    tmp.Draw(dest.Canvas, 0, 0);
  finally
    Tmp.Free;
  end;
end;
 
end.
Mon image faire bien une rotation de 90 ° mais elle est coupée.
Mon image de départ fait 800*600 pixels et à la sortie j'ai une image de 600*800 pixels mais tronquée.

Nom : a.png
Affichages : 202
Taille : 1,22 Mo

Nom : new_a.png
Affichages : 201
Taille : 815,1 Ko