Bonjour,

Je cherche actuellement à afficher des images (de 20x20px) sur lesquelles j'applique des rotations. (de 90, 180 ou 270°)
Cela fonctionne, mais ce n'est pas parfait, j'ai un décalage d'un pixel je pense dans certain cas.

C'est le code ci-dessous que j'utilise et qui me pose problème.

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
procedure TRotImgs.FormShow(Sender: TObject);
var
  iDroit, iDroite(*, iGauche*), iTmp: TBGRABitmap;
  chemin: String;
begin
  // création des images
  fond := TBGRABitmap.Create(Panel1.Width, Panel1.Height, BGRAWhite);
 
  chemin  := Application.Location + 'imgs\';
  iDroit  := TBGRABitmap.Create(chemin + 'droit.png' );
  iDroite := TBGRABitmap.Create(chemin + 'droite.png');
  //iGauche := TBGRABitmap.Create(chemin + 'gauche.png');
  itmp    := TBGRABitmap.Create(20, 20, BGRA(0, 0, 0, 0));
 
  // chargement des images
  iDroite.Draw(fond.Canvas, 50, 50);
  TRotImgs.RotateImage(iDroit, iTmp, 2);
  iTmp.Draw(fond.Canvas, 50 + 20, 50);
 
  TRotImgs.RotateImage(iDroite, iTmp, 2);
  iTmp.Draw(fond.Canvas, 50 + 40, 50);
  TRotImgs.RotateImage(iDroit, iTmp, 3);
  iTmp.Draw(fond.Canvas, 50 + 40, 50 + 20);
 
  TRotImgs.RotateImage(iDroite, iTmp, 3);
  iTmp.Draw(fond.Canvas, 50 + 40, 50 + 40);
  TRotImgs.RotateImage(iDroit, iTmp, 4);
  iTmp.Draw(fond.Canvas, 50 + 20, 50 + 40);
 
  TRotImgs.RotateImage(iDroite, iTmp, 4);
  iTmp.Draw(fond.Canvas, 50, 50 + 40);
  iDroit.Draw(fond.Canvas, 50, 50 + 20);
 
  FreeAndNil(iDroit);
  FreeAndNil(iDroite);
  //FreeAndNil(iGauche);
  FreeAndNil(itmp);
end;
 
procedure TRotImgs.FormDestroy(Sender: TObject);
begin
  FreeAndNil(fond);
end;
 
procedure TRotImgs.Panel1Paint(Sender: TObject);
begin
  if (Assigned(fond)) then
    fond.Draw(Panel1.Canvas, 0, 0);
end;
 
class procedure TRotImgs.RotateImage(imgOrg, imgRot: TBGRABitmap; rot: Integer);
// rotation d'une image : 2 = 90 / 3 = 180 / 4 = 270
begin
  if (rot < 2) or (rot > 4) then Exit;
 
  imgRot.PutImageAngle(imgOrg.Width  div 2,
                       imgOrg.Height div 2,
                       imgOrg,
                       90 * (rot - 1),
                       imgRot.Width  div 2,
                       imgRot.Height div 2);
end;
Si des gens sont motivés, je peux mettre le projet à dispo.
c'est juste un projet de tests.


Savez-vous ce qui ne vas pas dans mon code, ou comment le corriger ?